JSFiddle - React, Tailwind, and code Playground

by Ben Alman

HTML

<!--

Special events need a way to determine whether they are being bound with .bind vs .live/.delegate

See http://dev.jquery.com/ticket/6903

-->
<div></div>

JavaScript

(function($){
    
    // Special event definition.
    $.event.special.myevent = {
        setup: function() {
            var not_live = this != document;
            console.log( 'setup', not_live ? "DEFINITELY NOT LIVE" : "MIGHT BE LIVE (OR BIND OR DELEGATE)" );
        },
        add: function( handleObj ) {
            var selector = handleObj.selector,
                context = this;
            
            console.log( 'add',
                         selector ? 'EITHER LIVE OR DELEGATE selector: ' + selector : 'DEFINITELY BIND',
                         'context: ', context );
        }
    };
    
})(jQuery);

console.log( '1) .bind:' );
$('div').bind( 'myevent', function(){} );

console.log( '2) .bind:' );
$('div').bind( 'myevent', function(){} );

console.log( '3) .live:' );
$('div').live( 'myevent', function(){} );

console.log( '4) .live:' );
$('div').live( 'myevent', function(){} );

console.log( '5) .delegate:' );
$('body').delegate( 'div', 'myevent', function(){} );

console.log( '6) .delegate:' );
$('body').delegate( 'span', 'myevent', function(){} );