Why I get this JavaScript error with jQuery Validate?

Michael picture Michael · Jan 29, 2017 · Viewed 12k times · Source

I use jquery.unobtrusive and jquery.validate libraries in asp.net mvc 5 project to validate user registration on client side.

on browser I get this error:

Uncaught TypeError: $(...).parents(...).andSelf is not a function
    at Object.parse (jquery.validate.unobtrusive.js:211)
    at HTMLDocument.<anonymous> (jquery.validate.unobtrusive.js:392)
    at mightThrow (jquery-3.1.1.js:3570)
    at process (jquery-3.1.1.js:3638)

I use jquery 3.1.1 in my project.It seem to be versions problems.

Any idea how can I solve it?

Answer

Sparky picture Sparky · Jan 29, 2017

Uncaught TypeError: $(...).parents(...).andSelf is not a function

Read the jQuery docs.

"I use jquery 3.1.1 in my project."

The .andSelf() method was removed from jQuery version 3

It was an alias for the .addBack() method, which should be used instead.