I’m new to jQuery and have setup a function to toggle a div open/closed. Works great. But I have 6 places I need it on the page. So would like to change the id #show as a passed in variable to I can accomplish this for 6 divs using one jQuery function.
<script>
$(function(){
$('.myClass').hide();
$('#show').toggle(function(){
$('.myClass').slideDown("fast");
$(this).attr("src","/images/minus.png" );
},function(){
$('.myClass').slideUp("fast");
$(this).attr("src", "/images/plus.png" );
});
});
</script>
<h2><img id="show" src="/images/plus.png"><span class="toggleText">DivisionI</span>
</h2>
<div class="myClass">
my code to show....
</div>
1 Answer