09.15.2011
jQuery toggleText function
This is a simple function to toggle text contents of an HTML element with
jQuery. It should be easy to equip the toggleText methode with an array of strings.
/*
* jQuery.toggleText Plugin.
* Copyright (c) saquery.com
* Licensed under MIT - http://www.opensource.org/licenses/MIT
*/
$.fn.toggleText = function(txt){
return this.each(function(){
var _=$(this),_current=_.text(),_txt=txt;
if ( _current === txt){ _txt=_.data('oldvalue'); } else { _.data('oldvalue',_current); };
_.text(_txt);
});
};
Vote this page