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?

3
  • 3
    Well, .live() has been deprecated for a while; perhaps it's really gone now :) Commented Apr 25, 2013 at 14:55
  • 4
    try changing it to $(document).on('click', '.formError', function(){ ... }); Commented Apr 25, 2013 at 14:57
  • .live is gone as of 1.9, I think: jsfiddle.net/6mBsB Commented Apr 25, 2013 at 14:57

4 Answers 4

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
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but this has just broken it even more, now I have two more errors and it still doesn't work.
@Francesca what has it broken? Can you make a jsfiddle?
@Francesca 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.
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.

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.