Home >Web Front-end >JS Tutorial >How to Migrate from jQuery\'s Deprecated `.live()` to the `.on()` Method?
jQuery 1.9 .live() Error: Migration Guide
From version 1.9 onwards, jQuery has removed the .live() function. If you have recently upgraded from version 1.8 or earlier, you may encounter the error "TypeError: $(...).live is not a function." To resolve this issue, you can migrate to the new .on() method.
Migration Instructions:
The parameters for .live() and .on() differ. The following guidelines will help you migrate:
Migration Examples:
Example 1:
Before:
$('#mainmenu a').live('click', function)
After:
$('#mainmenu').on('click', 'a', function)
Example 2:
Before:
$('.myButton').live('click', function)
After:
$('#parentElement').on('click', '.myButton', function)
Or:
$(document).on('click', '.myButton', function)
Additional Resources:
The above is the detailed content of How to Migrate from jQuery\'s Deprecated `.live()` to the `.on()` Method?. For more information, please follow other related articles on the PHP Chinese website!