Reputation: 41
I would like to have a single button that when clicked it shows multiple divs (3 or more) at once, and then when clicked again it hides the divs. I have found answers for showing multiple divs one at a time but i would like all the divs to pop up at the same time and hide at the same time from one button. The divs will be styled differently. Im sorry if this has already been answered and thank-you in advance for any answers
Upvotes: 4
Views: 1042
Reputation: 303
Or you can use ordinary javascript (if you don't like jQuery) and call twice (or more) function for hiding html elements. Something like this:
<button onclick="divHideShow('divC');divHideShow('divD');">Click me</button>
Of course, divHideShow is function which hide div element. So call above hide divC and divD. Find detailed instructions on: Show or hide multiple divs.
Upvotes: 0
Reputation: 12368
Why don't you put a class say hiddenDiv
on all the divs that need to made hidden and use
$('#hideButton').click(function() {
$('.hiddenDiv').toggle();
});
Upvotes: 3
Reputation: 27594
Use this script:
$('#button-id').click(function(e) {
$('#id1, #id2').toggle();
e.preventDefault();
});
Upvotes: 0