live() method in jQuery 1.8
//Old live() method
$(".some .static .dynamic_elements").live('click',function(){
// something really cool
});
// New on() method
$(".some .static").on('click','.dynamic_elements',function(){
// it works !!
});
Enjoy :D
Written by Abimael Martell
Related protips
2 Responses
Also worth mentioning, on is specifically the equivalent of delegate (which was around when live was around as well). The difference is that .live (a) first had to select all of the elements you put in the selector before actually binding the event (a problem if your selector could select a lot of elements when you applied it) and (b) it installed the event handler on the document element every time. .delegate lets you instead install the event handler on a particular parent element (including the document element if you so wish) so that the event need not bubble as far and the document element isn't cluttered with too many event handlers.
over 1 year ago
·
@jeromesmadja from the jQuery site "As of jQuery 1.7, the .live() method is deprecated"
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Events
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#