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

4

16

Getting this error:

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

From this JavaScript and jQuery code:

init: function(options) {
  var form = this;
  if (!form.data('jqv') || form.data('jqv') == null ) {
    options = methods._saveOptions(form, options);
    // bind all formError elements to close on click
    $(".formError").live("click", function() {

      //Getting error here:
      //Uncaught TypeError: Object [object Object] has no method 'live'

    });
  }
  return this;
};

Why is method live missing?

React answered 25/4, 2013 at 14:54 Comment(3)
Well, .live() has been deprecated for a while; perhaps it's really gone now :)Containerize
try changing it to $(document).on('click', '.formError', function(){ ... });Whetstone
.live is gone as of 1.9, I think: jsfiddle.net/6mBsBInappreciable
K
31

.live was removed in jquery 1.9

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


Try using .on instead:

$(document).on('click', '.formError', function(){ 
   //your event function
});
Kittle answered 25/4, 2013 at 14:57 Comment(3)
Thanks but this has just broken it even more, now I have two more errors and it still doesn't work.React
@React what has it broken? Can you make a jsfiddle?Kittle
@React Could the two more errors just mean it actually got past that one line and progressed further to more errors that existed but aren't related to this one? More errors after fixing one isn't always a bad thing, it just means you have more information on the problem, and of course more errors to fix.Wedekind
J
7

According to the documentation, .live() has been deprecated since 1.7 and removed in 1.9.

You would either have to downgrade jQuery or use a newer version of the validation plugin, if it's available.

Jeanelle answered 25/4, 2013 at 14:57 Comment(0)
M
4

.live() removed

The .live() method has been deprecated since jQuery 1.7 and has been removed in 1.9. We recommend upgrading code to use the .on() method instead.

To exactly match

    $("a.foo").live("click", fn)

You should write

    $(document).on("click", "a.foo", fn).

For more information, see the .on() documentation. In the meantime, the jQuery Migrate plugin can be additionally used to restore the .live() functionality.

Maddiemadding answered 12/2, 2014 at 14:17 Comment(0)
C
1

There's a migrate library that helps you transition from previous versions of jQuery when upgrading: jQuery migrate plugin. You need to include it in your source after jQuery. From the jQuery site:

The uncompressed development version of the jQuery Migrate plugin includes console log output to warn when specific deprecated and/or removed features are being used. This makes it valuable as a migration debugging tool for finding and remediating issues in existing jQuery code and plugins. It can be used for its diagnostics with versions of jQuery core all the way back to 1.6.4.

The compressed version of the plugin does not generate any log output, and can be used on production sites when jQuery 1.9 or higher is desired but older incompatible jQuery code or plugins must also be used. Ideally this would only be used as a short-term solution, but that's a decision for you to make.

Craft answered 26/11, 2013 at 10:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.