The equivalent of:
$('a').live('click', function(){});
is this:
$(document).on('click', 'a', function(){});
But, .on()
is more powerful because rather than attach all event handlers to the document
object like .live()
does, you can pick a static parent that is much closer to your dynamic objects and will be more efficient, particularly if you have a lot of delegated event handlers.
For example if you had a container div called links, you would do this:
$("#links").on('click', 'a', function(){});
The selector in the jQuery object is the static object that you want the event handler bound to. The selector in the arguments to .on()
is a selector that matches the objects who's events you want to handle that will bubble up to your static parent object.