jQuery – use the “on()” method instead of “live()”

As of jQuery 1.7,the .live() method is deprecated.Use .on() to attach event handlers.

Description: Attach an event handler function for one or more events to the selected elements.
The .on() method attaches event handlers to the currently selected set of elements in the jQuery object.

.on(eventType, selector, function)

$(“body”).on(“click”, “#element”, function(){

$(“body”).on(“click” , “p” ,function(){

Migration from .live() to .on()
$(‘#mainmenu a’).live(‘click’, function)
after, you move the child element (a) to the .on() selector:
$(‘#mainmenu’).on(‘click’, ‘a’, function)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>