JSFiddle - React, Tailwind, and code Playground

by Dimitar Christoff

HTML

<p id="myp">click here to toggle</p>

JavaScript

(function() {
    var index = 0;
    Element.implement({
        toggle: function() {
            var args = arguments, count = args.length -1;
            return this.addEvent('click', function(){
                args[index].apply(this, arguments);
                index = (count > index) ? index+1 : 0;
            });
        }
    });
})();

$('myp').toggle(
    function(e) {
        console.log(e); // event.
        this.set('html', 'new text');
    },
    function() {
        console.log(this); // element
        this.set('html', 'old text');
    },
    function() {
        this.set("html", "function 3!");
    }
);