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
manuel arvizu
Courses Plus Student 3,030 Pointsjquery 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
Kevin Korte
28,149 Pointsis this what your css looks like:
.one-div {
display: none;
}
manuel arvizu
Courses Plus Student 3,030 Pointsim 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...
:)
Kevin Korte
28,149 PointsIs this what you wanted it to do?
manuel arvizu
Courses Plus Student 3,030 Pointsyes thanks Kevin but one more question, how can i hide the div one if i click the second :) in the javascript
Kevin Korte
28,149 Pointsmanuel arvizu
Courses Plus Student 3,030 Pointsthank you very much :) for the big help