jQuery: .delegate() vs .live() vs .on() vs .bind() vs .click/.mouseover/.mouseenter

The event binding functions like .click, .mouseover eventually trigger .bind() method and .bind eventually trigger .on() method, so .on() is most fastest however .on() doesnot work for dynamically added elements. SO for dynamically added elements use .live() or .delegate()

However, .live() searches the element within whole document and .delegate() searches the element within the area you specify so, .delegate() is the most efficient method to bind an event.

Slowest ----> Faster
.click() --> .bind() --> .on()

.live() --> .delegate()
element.on('click', function () { ... });
element.bind('click', function () { ... });
element.click(function () { ... });
element.on('selector', 'click', function () { ... });
element.delegate('click', 'selector', function () { ... });
$('selector').live('click', function () { ... });

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s