Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object has no method 'live' - jQuery

<script> $(document).ready(function(){     $('.delete').live('click', function(e){         alert('delete');         e.preventDefault();     }); }); </script> <a href='#' id='_1' class='delete'>Delete</a> 

Gives me an error:

Uncaught TypeError: Object [object Object] has no method 'live'

I just don't see the problem?

like image 444
reggie Avatar asked Jan 25 '13 16:01

reggie


2 Answers

.live() is a deprecated function (from 1.7+) and removed completely from jQuery 1.9+.

You can instead use .on() or .bind() methods:

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

like image 113
diggersworld Avatar answered Oct 05 '22 11:10

diggersworld


  1. If the call to .live() is inside your own code, just change it to .on() using the rules shown at http://api.jquery.com/live.

  2. If the code is in a third-party jQuery plugin, use the jQuery Migrate plugin to restore .live() until the author updates their plugin: https://github.com/jquery/jquery-migrate#readme.

  3. In production sites, do not use URLs that reference the "latest" version of jQuery such as http://code.jquery.com/jquery-latest.js or http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js since they will automatically update when a new version of jQuery is released and your site will suddenly break if it is not compatible.

like image 44
Dave Methvin Avatar answered Oct 05 '22 12:10

Dave Methvin