Hello All,
I have been trying to get this function to work for awhile now. I have 11 different divs that are hidden by default. Each have a "trigger" button that is supposed to get them to pop open. I was able to do this with a much longer series of functions for each specific div (which ended up being about 175 lines of code!). I wanted to condense it down into a single function that would do the same thing ie: trigger 1 is clicked - div 1 opens/ trigger 1 is clicked again, div 1 closes etc, etc.
Here is my script as of now
$(document).ready(function() {
$("[class^='ShowVehicles']").toggle(function() {
alert("click happened");
$("[class^='HiddenVehicles']").slideDown(1000);
},
function () {
$("[class^='HiddenVehicles']").slideUp(1000);
});
});
It's currently opening all "HiddenVehicles" divs and I need to make it more specific. I'm fairly new to jquery so I have pretty much run out of ideas. Thanks in advance guys!
Edit - Thanks for all the help guys, here's the solution I came up with:
$(document).ready(function() {
$("div.WrapIt").toggle(
function(){ $(".HiddenVehicles", this).slideDown(1000);
$("img.imgSwap" , this).attr("src","assets/images/SelectBySize/SelectBySize_HideAll.gif");
},
function(){ $(".HiddenVehicles", this).slideUp(1000);
$("img.imgSwap" , this).attr("src","assets/images/SelectBySize/SelectBySize_ShowAll.gif")
}
);
$(".ShowEveryThing").toggle(
function() { $(".WrapIt .HiddenVehicles").slideDown(1000);
$("img.imgSwap").attr("src","assets/images/SelectBySize/SelectBySize_HideAll.gif");
$("img.buttonSwap").attr("src","assets/images/SelectBySize/SelectBySize_HideBtn.gif");
},
function(){ $(".WrapIt .HiddenVehicles").slideUp(1000);
$("img.imgSwap").attr("src","assets/images/SelectBySize/SelectBySize_ShowAll.gif");
$("img.buttonSwap").attr("src","assets/images/SelectBySize/SelectBySize_ShowBtn.gif");
});
});
I created a wrapper div and had the function fire when that div was clicked. I also included some image swapping and a show all function.