javascript - Is there an advantage to using jQuery's $().on('mouseenter',function(){}) over $().mouseenter(function(){})? -


i see code like:

$("#thing").on("mouseenter",function(){ stuff }); 

personally, write:

$("#thing").mouseenter(function(){ stuff }); 

similarly, write

$("#thing").click(function(){}) 

but have seen people correct (yes, know on preferred on bind in v. 1.7+, it's same preference issue):

$("#thing").bind("click",function(){})  

am doing "wrong", there deep difference between 2 functions i'm not seeing? seems want do, it's never been practical concern, i'd interested know if there's theoretical consideration i'm overlooking.

not really, it's little faster mouseenter function calls on (or trigger if called without argument) can seen in source code :

jquery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +     "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +     "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {      // handle event binding     jquery.fn[ name ] = function( data, fn ) {         return arguments.length > 0 ?             this.on( name, null, data, fn ) :             this.trigger( name );     }; }); 

as can see, same can said many events.

personally, prefer use mouseenter (or click, etc.) function when don't need special features of on : 1 of big advantages in opinion in using jquery makes code less verbose , more readable. , don't think should corrected, ask guys corrects why that.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -