Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

jquery problem.... toggle or hide between to buttons

this is my jquery for toggle or hide a div on my css on click...

can anyone tell me what im doing wrong... thank you very much.

this its my html and javascript... in the css div im using display:none;

<nav id="header">
<ul>
<li class="one"><a href="#">one</a></li>
<li class="two"><a href="#">two</a></li>
</ul> 
</nav>   
<div class="one-div">
<div>
<h1>title</h1>
<p>text here</p>
</div>
</div>
<div class="two-div">
<div>
<h1>title</h1>
<p>text here</p>
</div>
</div>


$('.one').click(function() {
if ($(".one-div").is(":hidden")) {
    $(".one-div").slideDown("slow");
} else {
    $(".one-div").hide();
}

});

 $('.two').click(function() {
if ($(".two-div").is(":hidden")) {
    $(".two-div").slideDown("slow");
} else {
    $(".two-div").hide();
}
 });

6 Answers

is this what your css looks like:

.one-div {
     display: none;
}

im using that on my css for the two div's

for example i click the one and display ok but if i click the second one a wierd behavior starts like not hidde the first one before displaying the the second one...

:)

Is this what you wanted it to do?

http://jsfiddle.net/uEmhV/3/

yes thanks Kevin but one more question, how can i hide the div one if i click the second :) in the javascript

Something like this?

http://jsfiddle.net/uEmhV/4/

I just used the .hide()

thank you very much :) for the big help