/ Published in: jQuery
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$('#img').toggle(function() { $('#div').show('slow'); $('#img').attr('src', 'root/images/minus.gif'); }, function() { $('#div').hide('fast'); $('#img').attr('src', 'root/images/plus.gif'); }); });