Reputation: 843
I have 4 div, a b c d, use Jquery toggle
to open and close, each one close by it self.
There is also one button can close and open all.
However if user click 'b' first, than click 'close all' button. it will become. a, c, d close, b open. Is any way to make one button hide
than change function to show
?
$(document).ready(function(){
$(".toggle").click(function(){$(this).next("div").slideToggle(300);});
$("#collapse").click(
function(){
$(".content").toggle();
}
);
});
Upvotes: 3
Views: 193
Reputation: 205987
$(".toggle").click(function () {
$(this).next(".content").slideToggle(300);
});
var io = 0;
$("#collapse").click(function () {
$(".content")[io++%2?'show':'hide']();
});
where also, if you like, instead of 'show':'hide'
you can use 'slideDown':'slideUp'
http://jsfiddle.net/vyPHZ/3/
Upvotes: 3
Reputation: 8623
You can use one extra class for the state of the $.content
, then check it when deciding to hide or show:
Upvotes: 2