Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Help me! Please! Multiple .Slidetoggle Re: Help me! Please! Multiple .Slidetoggle

#46750
DogsGhost
Member

You have to give each button and div involved a unique class or ID so so the js knows what to toggle. So it would look something like this:

$(function(){
//hide everything with class of Portfolio
$('.Portfolio').hide();
//toggle specific portfolio when you click a specific button
$('#button1').click(function(){
$("#Portfolio1").slideToggle();
});
$('#button2').click(function(){
$("#Portfolio2").slideToggle();
});
$('#button3').click(function(){
$("#Portfolio3").slideToggle();
});
});

You can set up an array (I think that’s what its called) at the start that says like “#button1″:”Portfolio1″,”#button2″:”Portfolio2”,etc. to avoid the repeating code.