Posted By

mikemetcalf on 10/01/09


Tagged

show toggle hide jquery text


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

shabbar


Toggle more text


 / 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.

  1. $('.toggle').click(function() {
  2. var $this = $(this);
  3. if ('[+]' == $this.text( )) {
  4. $this.text('[-]').parent( ).find('.hidden').show( );
  5. }
  6. else {
  7. $this.text('[+]').parent( ).find('.hidden').hide( );
  8. }
  9. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: shabbar on November 4, 2009

this script is not working

You need to login to post a comment.