Last Updated: February 25, 2016
·
2.214K
· abimaelmartell

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

2 Responses
Add your response

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 ·