Tek Tek - 14 days ago 5
Javascript Question

jquery 3.1.1 Error: Object doesn't support property or method 'andSelf'

I just NuGet update my jquery from 1.8.3 to 3.1.1.
Then I keep getting this error on every page. After looking around, it seem like jquery is getting execute multiple times, but that doesn't seem to be the case when I check in developer tool.

So, this is where it happens.

jQuery.Deferred.exceptionHook = function( error, stack ) {

// Support: IE 8 - 9 only
// Console exists when dev tools are open, which can happen at any time
if ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) {
window.console.warn( "jQuery.Deferred exception: " + error.message, error.stack, stack );
}
};

jQuery.readyException = function( error ) {
window.setTimeout( function() {
throw error;
} );
};


On line "window.console.warn...." it has warning -
jQuery.Deferred exception: a(...).parents(...).andSelf is not a function

And the error is thrown on line "thrown error" -
Uncaught TypeError: a(...).parents(...).andSelf is not a function

Any idea why this happens?

Answer

jQuery deprecated andSelf in version 1.8 and removed it in version 3.0.0, which is why it's "not a function" in 3.1.1.

You should be using $.fn.addBack instead, but the code you've posted is the part of jQuery that handles errors, this is not the problem, somewhere in your code there's a piece of code that says a(...).parents(...).andSelf() which should be changed to a(...).parents(...).addBack().