Toggle more text


/ Published in: jQuery
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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

You need to login to post a comment.