12

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?

0

2 Answers 2

21

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.

Sign up to request clarification or add additional context in comments.

Comments

13

Like @Sparky said, this is because the Unobtrusive JS files obtained from NuGet (if you create an app using File->New in Visual Studio) uses the deprecated andSelf() function.

To resolve, get the latest versions of

jquery.validate.unobtrusive.js jquery.validate.unobtrusive.min.js

from

https://github.com/aspnet/jquery-validation-unobtrusive/tree/master/dist

and replace the ones in your project. Or Download / Update exiting plugin from nuget.

After Replacing Make sure you clear your browser cache. (Control + F5 if you are using chrome)

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.