jQuery Snipped for toggle text inside div on click.
"Hello World" will be default text and text for every second click.
And "Bye!" will be on first and every even click.
jQuery.fn.extend({
toggleText: function (a, b){
var isClicked = false;
var that = this;
this.click(function (){
if (isClicked) { that.text(a); isClicked = false; }
else { that.text(b); isClicked = true; }
});
return this;
}
});
jQuery('.toggle-text').toggleText("Hello World", "Bye!");