jQuery’s .bind() vs. .on()

Samuel picture Samuel · Aug 7, 2012 · Viewed 144.3k times · Source

I found two great articles talking about the new function .on(): jquery4u.com, elijahmanor.com.

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

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

$("#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 exists 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, should .on() be used instead of .bind() even if I don’t use the other features provided by the .on() function?

Answer

Blazemonger picture Blazemonger · Aug 7, 2012

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.