JSFiddle - React, Tailwind, and code Playground

by JakobJingleheimer

HTML

<div id="me">hello</div>

JavaScript

$.fn.bindFirst = function(name, fn) {
    // bind as you normally would
    // don't want to miss out on any jQuery magic
    this.bind(name, fn);
    var handlers = this.data('events')[name];
    // take out the handler we just inserted from the end
    var handler = handlers.splice(handlers.length - 1)[0];
    // move it at the beginning
    handlers.splice(0, 0, handler);
};

$(function() {
    $("#me").click(function() { alert("1"); });
    $("#me").click(function() { alert("2"); });    
    $("#me").bindFirst('click', function(event) {
        if ( ! confirm("3") ) event.stopImmediatePropagation();
    });
    
    $("#me").click();
});