I recently updated jQuery from 1.8 to 2.1. I suddenly discovered that the .live() stops working.
I get the error TypeError: $(...).live is not a function.
Is there any method I can use in place of .live()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
jQuery
.live()has been removed in version 1.9 onwardsThat means if you are upgrading from version 1.8 and earlier, you will notice things breaking if you do not follow the migration guide below. You must not simply replace
.live()with.on()!Read before you start doing a search and replace:
For quick/hot fixes on a live site, do not just replace the function
livewithon,as the parameters are different!
should map to:
The (child) selector is very important! If you do not need to use this for any reason, set it to
null.Migration Example 1:
before:
after, you move the child element (
a) to the.on()selector:Migration Example 2:
before:
after, you move the element
.myButtonto the.on()selector, and find the nearest parent element (preferably with an ID):If you do not know what to put as the parent,
documentalways works:See also: