JSFiddle - React, Tailwind, and code Playground
by stecb
HTML
<p id="myp">click here to toggle</p>
JavaScript
Element.implement({
toggle: function(fn1,fn2){
this.store('toggled',false);
return this.addEvent('click',function(event){
event.stop();
if(this.retrieve('toggled')){
fn1.call(this);
}else{
fn2.call(this);
}
this.store('toggled',!(this.retrieve('toggled')));
});
}
});
$('myp').toggle(
function() {
this.set('html', 'new text');
},
function() {
this.set('html', 'old text');
}
);