Return to Snippet

Revision: 33260
at October 7, 2010 09:24 by mattvbiggs


Initial Code
$('#img').toggle(function() {
   $('#div').show('slow');
   $('#img').attr('src', 'root/images/minus.gif');
 }, function() {
   $('#div').hide('fast');
   $('#img').attr('src', 'root/images/plus.gif');
 });
});

Initial URL

                                

Initial Description
I know there are other solutions and sites out there that provide code to perform this simple animation but I like the way I laid out the code. The principal behind this code is it will toggle a show or hide event and change your plus or minus image to correlate with the respective layout. In the snippet below the references to #img and #div should refer to the id attribute you set, not to the actual img and div tags.

Initial Title
JQuery: Toggle Expand/Collapse

Initial Tags
jquery

Initial Language
jQuery