Sunday, February 19, 2012

Toggle element JQuery

I don't who code this snippet but i like it :-)
(I also know there is the toggle function from JQuery)

Togger = function (e) {
    // Show the paragraph if it's hidden.
    var $paragraph = $(e.data);
    var $link = $(this);
    if ($paragraph.is(':hidden')) {
      $paragraph.show();
      $link.text('Click to hide');
     
    }
    // Hide the paragraph if it's visible.
    else {
      $paragraph.hide();
      $link.text(' Click to show');
    }
  };


$('#toggle-link-1').bind('click','#paragraph-1', Togger);
$('#toggle-link-2').bind('click','#paragraph-2', Togger);

No comments:

Post a Comment