Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7967569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:56:44+00:00 2026-06-04T06:56:44+00:00

The following works to replace a div with a new div… <div id =

  • 0

The following works to replace a div with a new div…

<div id = "div1" style="display:block" onclick = "replace()"><img src="1.jpg" /></div>

<div id = "div2" style="display:none"><img src="2.jpg" /></div>

<script type = "text/javascript">
function replace() {
document.getElementById("div1").style.display="none";
document.getElementById("div2").style.display="block";
}

</script>

What I can’t figure out is how to make this work so when you click div2 it is replaced by div3 and so on.

In other words, I want to replace the div on each click more than just once. What’s the best way to go about this? I’m a novice, so not sure if the above is a good start or not.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:56:45+00:00Added an answer on June 4, 2026 at 6:56 am

    You could make a more generic function:

    function replace( hide, show ) {
      document.getElementById(hide).style.display="none";
      document.getElementById(show).style.display="block";
    }
    

    Then you can create many divs and use the same function:

    <div id = "div1" style="display:block" onclick = "replace('div1','div2')">...</div>
    <div id = "div2" style="display:none" onclick = "replace('div2','div3')">..</div>
    <div id = "div3" style="display:none" onclick = "replace('div3','div4')">..</div>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML. <p><img src=myimage.jpg />This is my text</p> And the following
I have the following table in my HTML: <div style=max-width:700px;> <table border=1> <tr><td colSpan=2>this
I have written a HTML page which has following code. <div id=adsListContainer style=margin: 5px;>
Using jquery.load() to replace the content of a div everything works great, however there
I've got the following code: Regex.Replace(text, words.ToString(), <dfn title=\ + this.FindDefinition($0) + \>$0</dfn>, RegexOptions.IgnoreCase
Following works fine in shell: >>> from django.contrib.auth.models import User >>> user=User.objects.get(pk=1) >>> user.first_name
The following works in current Firefox (PDF loads), but not in current IE (page
The following works: public Date getDate() { return date; } and produces something like:
The following works as expected. awk -F'^' '{printf set %s:%s %s\n,$1,$2, $7}' todel.txt |
I know that the following works but it is not that readable, is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.