jquery - Replace live() with on() -


from documentation

$(selector).live(events, data, handler);                // jquery 1.3+ $(document).delegate(selector, events, data, handler);  // jquery 1.4.3+ $(document).on(events, selector, data, handler);        // jquery 1.7+ 

i'm using jquery 1.7.1

this works, static elements , dynamically loaded elements:

$("input").live("change", function () { alert("hello"); }); 

this doesn't work, not static elements:

$("document").on("change", "input", function () { alert("hello"); }); 

what missing?

write like

$(document).on("change", "input", function () { alert("hello"); }); 

you can replace document closer parent element exist in dom better performance. like

$('#closest_static_container_id').on("change", "input", function () {       alert("hello");  }); 

if use $("document") jquery search node/tag named document <document> , wont find document object.

but use $("body") body node/element of dom.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -