How to toggle a text using jQuery

To toggle a text using jQuery you can use the following snippet.

Sample jQuery

jQuery.fn.toggleText = function(textOne, textTwo) {
	return this.each(function() {
		jQuery(this).text(jQuery(this).text() == textOne ? textTwo : textOne);
	});
};

Please Share us:
Please rate this snippet

3 thoughts on “How to toggle a text using jQuery

Leave a Reply