Samuel Samuel - 5 months ago 7
Javascript Question

jquery .bind() vs. .on()

I found two great articles talking about the new function .on().

Is there any ways where the .bind() still be better to use than .on()?

For example: I have a sample code that look like that:

$("#container").click( function( e ) {} )

You can note that I just have one item retrieved by the selector and in my case, the div named #container already exist when my page was loaded; not added dynamically. It's important to mention that I use the latest version of jquery; 1.7.2.

For that sample, is .on() should be used instead of .bind() even if I don't use the other features provided by the .on() function?


Internally, .bind maps directly to .on in the current version of jQuery. (The same goes for .live.) So there is a tiny but practically insignificant performance hit if you use .bind instead.

However, .bind may be removed from future versions at any time. There is no reason to keep using .bind and every reason to prefer .on instead.