Can event delegation be implemented if the jQuery .on() receives only two parameters? -


i reading delegated events @ https://learn.jquery.com/events/event-delegation/ , http://api.jquery.com/on/. examining following syntax:

.on( events [, selector ] [, data ], handler ) 

in order implement event delegation, optional [, selector ] in syntax above must used, correct? example, not implementing event delegation (notice how .on() receiving 2 parameters):

// attach directly bound event handler $( "#list a" ).on( "click", function( event ) {     event.preventdefault();     console.log( $( ).text() ); }); 

this implementing event delegation (notice how .on() receiving more 2 parameters):

// attach delegated event handler $( "#list" ).on( "click", "a", function( event ) {     event.preventdefault();     console.log( $( ).text() ); }); 

can event delegation implemented if jquery .on() receives 2 parameters? impression is not possible have confirmation. thank you.

technically can. optional selector parameter checked against event target behind scenes, , executes handler function if there match. nothing stopping writing own delegation. example:

$( "#list" ).on( "click", function( event ) {     event.preventdefault();     if( event.target.nodename === ) {         console.log( $( ).text() );     } }); 

but yes, pointless, , understanding correct.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -