Skip to content

Instantly share code, notes, and snippets.

@cwardzala
Created August 18, 2011 21:07
Show Gist options
  • Save cwardzala/1155208 to your computer and use it in GitHub Desktop.
Save cwardzala/1155208 to your computer and use it in GitHub Desktop.
toggleText plugin for jQuery
/**
* textToggle jQuery Plugin
* Written By: Cameron Wardzala
*
* Usage: $(selector).textToggle('foo','bar');
*/
jQuery.fn.toggleText = function (a,b) {
return this.each(function () {
var $t = $(this);
if ($t.text() === a){
$t.text(b);
} else if ($t.text() === b) {
$t.text(a);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment