I have a question about some functionality that I am trying to add to my jQuery to include a button or text to expand / assemble all divs on click ... and I would like to figure out how to save the first div when the page loads.
Here is jQuery:
(document).ready(function(){
$(".toggle_container").hide();
$("h2.trigger").toggle(function(){
$(this).addClass("active");
}, function () {
$(this).removeClass("active");
});
$("h2.trigger").click(function(){
$(this).next(".toggle_container").slideToggle("slow");
});
});
And css:
// uses a background image with an on (+) and off (-) state stacked on top of each other
h2.trigger { background: url(buttonBG.gif) no-repeat;height: 46px;line-height: 46px;width: 300px;font-size: 2em;font-weight: normal;}
h2.trigger a {color:
h2.active {background-position: left bottom;}
.toggle_container { overflow: hidden; }
.toggle_container .block {padding: 20px;}
And html
<h2 class="trigger"><a href="#">Heading</a></h2>
<div class="toggle_container">
<div class="block">Stuff goes here</div>
</div>
<h2 class="trigger"><a href="#">Heading 2</a></h2>
<div class="toggle_container">
<div class="block">Stuff goes here</div>
</div>
This way it works great and looks great. However, when I try to get it to open the first instance, the background image that needs to be adjusted shows the state (-), does not change. The code I used for this:
$(".toggle_container:first").show();
, : - / ? , - , all/close all?
!