/ Published in: jQuery
Example markup:
<p>This is the first part of the text <a class="toggle">[+]</a><span>this part is hidden until clicking the toggle link.</span></p>
The script will show and hide text when the toggle link is clicked. It also swaps out the + with the − when the the text is toggled.
<p>This is the first part of the text <a class="toggle">[+]</a><span>this part is hidden until clicking the toggle link.</span></p>
The script will show and hide text when the toggle link is clicked. It also swaps out the + with the − when the the text is toggled.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$('.toggle').click(function() { var $this = $(this); if ('[+]' == $this.text( )) { $this.text('[-]').parent( ).find('.hidden').show( ); } else { $this.text('[+]').parent( ).find('.hidden').hide( ); } });