Skip to content

Instantly share code, notes, and snippets.

@mayoz
Last active December 18, 2015 11:49
Show Gist options
  • Save mayoz/5778015 to your computer and use it in GitHub Desktop.
Save mayoz/5778015 to your computer and use it in GitHub Desktop.
/*!
* toggleText
* $(element).toggleText ( [text] );
*
* mit license. sercan cakir. 2012.
*/
$(function () {
$.fn.toggleText = function (text) {
var string = this.attr('data-toggle-text');
if (typeof attr == 'undefined' || attr == '') {
if (typeof text != 'undefined') {
string = text;
}
}
/* -- toggle text */
if (typeof string != 'undefined') {
var val = this.text();
this.text(string).attr('data-toggle-text', val);
}
/* -- for chaining */
return this;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment