Reputation: 1384
I have this JS Code to slide DIVs up and down:
$(".desc_div").slideUp();
$(".open_div").click(function(){
$(this).next(".desc_div").slideToggle("slow");
});
how can i make it so when a second div is expanded the other open one will close?
Upvotes: 0
Views: 1222
Reputation: 4980
This is working fine:
$(".desc_div").slideUp();
$(".open_div").click(function(){
$(this).next(".desc_div").slideToggle("slow");
$('.desc_div').hide()
$(this).next(".desc_div").show()
});
Upvotes: 0
Reputation: 1524
use .siblings() - it picks all neighbours of element excluding itself.
$(".open_div").click(function(){
$(this).next(".desc_div").slideToggle("slow").siblings('.desc_div').slideUp();
});
http://jsfiddle.net/acrashik/MaW35/7/
Upvotes: 2