Why I get this JavaScript error with jQuery Validate?
Solution 1
Uncaught TypeError: $(...).parents(...).andSelf is not a function
"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.
Solution 2
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)
Michael
Updated on June 05, 2022Comments
-
Michael almost 2 years
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?