Created
January 17, 2014 11:52
-
-
Save danieldunderfelt/8472218 to your computer and use it in GitHub Desktop.
Quick and dirty jQuery plugin to toggle an element's text between two alternatives.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Daniel Dunderfelt | |
* | |
* Use: $(element).toggleText("text alternative 1", "text alternative 2"); | |
*/ | |
(function($) { | |
$.fn.extend({ | |
toggleText: function(toggle1, toggle2) { | |
return this.each(function(i, ele) { | |
var currentText = $(ele).text(); | |
if(currentText === toggle1) { | |
$(ele).text(toggle2); | |
} | |
else { | |
$(ele).text(toggle1); | |
} | |
}); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment