Replacing jQuery live with on

.live() function is removed on jQuery version 1.9.

So if you want the same behaviour, you can use on with versions gte 1.9.

Let’s say we have a code that’s like:

$(“#serviceItemsContainer input“).live(“change”, function(){ /* some code */ });

then this code block can be changed like that:

$(“#serviceItemsContainer”).on(“change”, “input”, function(){ /* some code */ });

Notice, there is an extra parameter to pass the function as a selector. This way you can attach a function without having the item on DOM, when you execute the code.

Happy Coding

References:

https://api.jquery.com/live/

http://api.jquery.com/on/

http://weblog.west-wind.com/posts/2013/Jun/12/Replacing-jQuerylive-with-jQueryon

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s