Changing the menu text with jQuery

If you need to toggle the menu text client-side when you click it some JavaScript is required. This is best done with a framework like jQuery. All you need is an event handler bound to the menu item. It uses a counter variable to store the state which will be checked for oddness. If it’s odd use the one otherwise the other text.

Show only defect entries

<script type="text/javascript">
  jQuery(document).ready( function(){
    var flip = 0;
    jQuery('#owad_show_defects').bind( "click", function(e){
      flip++;

      if ( flip % 2 == 0 )
        jQuery('#owad_show_defects').text('Show all entries');
      else
        jQuery('#owad_show_defects').text('Show only defect entries');

    });
  });
</script>
DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>