Object does not have 'live' method - 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] does not have a 'live' method

I just do not see the problem?

+44
javascript jquery live
Jan 25 '13 at 16:26
source share
7 answers

.live() is an obsolete function (from 1.7+) and is completely removed from jQuery 1.9 +.

Instead, you can use the .on() or .bind() methods:

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

+122
Jan 25 '13 at 16:27
source share
+13
Jan 25 '13 at 16:52
source share

If you are using jQuery 1.7+, use on(...) instead of live(...) .
Check this out: http://api.jquery.com/on/

+3
Jan 25 '13 at 16:28
source share

There is one scenario where neither .on () nor .bind () will work: when the element does not exist when adding an event handler. And it was like living ().

+3
Feb 25 '13 at 19:08
source share

See http://api.jquery.com/live/

old

 $("a.offsite").live("click", function(){ alert("Goodbye!"); }); // jQuery 1.3+ $(document).delegate("a.offsite", "click", function(){ alert("Goodbye!"); }); // jQuery 1.4.3+ 

new

 $(document).on("click", "a.offsite", function(){ alert("Goodbye!"); }); // jQuery 1.7+ 
+3
Jun 08 '13 at 11:15
source share

use .on

 <script> $(document).ready(function(){ $('.delete').on('click', function(e){ alert('delete'); e.preventDefault(); }); }); </script> 
+1
Jan 25 '13 at 16:29
source share

There is a jQuery migration plugin (use this) ....... it will solve the problem.

ASP.NET MVC ajax-unobtrusive + jQuery 1.9 http://bugs.jquery.com/ticket/13220

0
Feb 07 '13 at 18:07
source share



All Articles