Show 1 extra DIVs when clicking a button, then another.

Hi,
I have a page set up with some DIVs in it, 1 - 5. DIVs 1, 2 and 3 are shown when the page loads but four and five are hidden. There is a button at the bottom when it is clicked once div 4 is displayed. When it is clicked again DIV 5 is shown. That's it. I've managed to get it working with extra buttons but cannot get the same button to add the 2 divs. Using JQuery BTW.

<html>
	<head>
		<title>Hello</title>


  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <script>
  $( "button" ).click(function() {
    
    //click once show div class four
    //click again show div class five    
  });
</script>
  </head>
  <body>
    <div class="one">
      Something one
    </div>
    <div class="two">
      Something two
    </div>
    <div class="three">
      Something three
    </div>
    <div class="four" style="visibility:hidden">
      Something four
    </div>
    <div class="five" style="visibility:hidden">
      Something five
    </div>
    
    <button>Add Another</button>

  </body>
</html>

Open in new window


Thanks in advance.

A
abigulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
this code works when you change your HTML from
style="visibility:hidden"
to
style="display:none"
$(document).ready(function(){
  $( "#showme" ).click(function() {
    if ($("div.four").is(":hidden")) {
      $("div.four").show();
    } else
      {
        $("div.five").show();
      }   
  });
});

Open in new window


Live sample:
http://jsbin.com/hoyuso/82/edit
HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abigulAuthor Commented:
Thanks, simple!
Julian HansenCommented:
An alternative approach - requires hiding your <div>'s with display: none rather than visibility: hidden

This method will work with any number of hidden div's. Each click will simply show the next one in the list by finding the last visible one and selecting the next after it.

<html>
<head>
<title>Hello</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
  $("button" ).click(function() {
    $('div:visible:last').next().show();
  });
});
</script>
</head>
<body>
<div class="one">
  Something one
</div>
<div class="two">
  Something two
</div>
<div class="three">
  Something three
</div>
<div class="four" style="display: none">
  Something four
</div>
<div class="five" style="display: none">
  Something five
</div>
<button>Add Another</button>
</body>
</html>

Open in new window

Working sample here http://www.marcorpsa.com/ee/t793.html
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.