Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Created August 12, 2010 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sindresorhus/521072 to your computer and use it in GitHub Desktop.
Save sindresorhus/521072 to your computer and use it in GitHub Desktop.
jQuery plugin - Toggle between the current and supplied text
$.fn.toggleText = function(b) {
return this.each(function() {
var $this = $(this);
if ( !$this.data('text') ) {
$this.data( 'text', $this.text() );
}
$this.text( $this.text() !== b ? b : $this.data('text') );
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment