With the newer jQuery .click(), .submit(), etc. was replaced by:
$('#foo').on('click', function() {
//
});
in terms of best practice. Did anything similar happen to .live()? Or is this still the best way to do it?
$('#foo').live('click', function() {
//
});
On() has all the abilities of all other bindings. To bind to dynamic elements you can use
on()like this:Preferably you want to use a close static element instead of
document.To quote from another post of mine regarding the many binding methods jQuery has on offer:
You can see the full post here, which also list the many drawbacks of
live()and why it should not be used any more in jQuery 1.7 or later.