Can someone help me out with this code, i assume its easy if you know how..?
Currently click to toggle box appears below.
I need it so when you click on the other toggle, the box currently open closes, so its basically impossible for them to be both open at the same time?
But you can still toggle each individual one open/closed as normal, just when its open the other one (if open) closes also.
So far.. http://jsfiddle.net/CkTRa/380/
Thank you.
UPDATE:
Can it work with targeting independent boxes like so...?
HTML:
<div>
<h3 class = "trigger"> <a href="#box1">Heading 1</a></h3>
</div>
<div>
<h3 class = "trigger"><a href="#box2">Heading 2</a></h3>
</div>
<div class = "toggle" id="box1">
box one content
</div>
<div class = "toggle" id="box2">
box two content
</div>
jQuery so far:
$(".trigger").click(function(){
$(this).next(".toggle").slideToggle("slow");
});
I think this simple code should work perfectly
$(".trigger").click(function(){
$(".trigger").not(this).next(".toggle").slideUp("slow");
$(this).next(".toggle").slideToggle("slow");
});
See jsFiddle demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With