...

View Full Version : Jquery Toggle Question



spadez
02-19-2010, 11:25 AM
Im using the toggle script demonstrated here:
http://www.sohtanaka.com/web-design/examples/toggle/

It works perfectly, but im wondering if it is possible to have a button to expand all and contract all.

Ive been reading through this page: http://api.jquery.com/toggle/

Im having a hard time understanding it, because this is one of the first things I have worked on with jquery. Can anyone help explain how I can do this?

mike182uk
02-19-2010, 12:19 PM
$(document).ready(function(){

$("h2.trigger").click(function(){
$(".toggle_container").slideToggle("slow,");
});


})


using the code from the website you shown this would make all containers open close whenever a h2 is clicked. you can change what calls it by changing this bit



$("h2.trigger")


to whatever your button class or id is

i.e



$(document).ready(function(){

$(".toggler").click(function(){
$(".toggle_container").slideToggle("slow,");
});


})



so you would give a link with a class of toggler, this would then toggle the divs to open or close.

spadez
02-19-2010, 01:28 PM
I would need it to expand all / contact all with one click of the button though, currently it only works one at a time.

mike182uk
02-19-2010, 01:37 PM
i wrote this above, sorry i may not of been clear.




$(document).ready(function(){

$("YOUR BUTTON CLASS OR ID").click(function(){
$(".toggle_container").slideToggle("slow");
});


})



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum