JSFiddle - React, Tailwind, and code Playground
by André Albson
HTML
<div>1. div (click me)</div><br />
<div>2. div (click me)</div>
JavaScript
(function($) {
$.fn.clickToggle = function(func1, func2) {
var funcs = [func1, func2];
this.data('toggleclicked', 0);
this.click(function() {
var data = $(this).data();
var tc = data.toggleclicked;
$.proxy(funcs[tc], this)();
data.toggleclicked = (tc + 1) % 2;
});
return this;
};
}(jQuery));
$('div').clickToggle(function() {
alert('First handler: ' + $(this).text());
}, function() {
alert('Second handler: ' + $(this).text());
});