$('#HideShow').click(function() { if ($(this).text() == "Show") { $(this).text("Hide"); } else { $(this).text("Show"); }; });
Alternative, .toggle () has .toggle (even, odd); the functionality, use that ever makes the most sense to you is a bit shorter code, but perhaps less specific.
$('#HideShow').toggle(function() { $(this).text("Hide"); HideClick('hide'); }, function() { $(this).text("Show"); HideClick('hide'); } );
NOTE. You can include any other actions that you want to use in function () as necessary, and you can remove onclick in markup / html by calling the HideClick () function call. as shown in the second example.
As a continuation and to introduce an alternative, you can add a CSS class to your CSS
.hideStuff { display:none; }
THEN add this to:
.toggle('.hideStuff');
or, more directly: in the appropriate place.
.addClass('.hideStuff'); .removeClass('.hideStuff');
Mark schultheiss
source share