Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: Uncaught TypeError: $(...).error is not a function

Tags:

jquery

I am using jquery on my page and don't have problem with other parts. Even $.post and $.get are working fine.

Now I am trying to evaluate if an image has any problems and tried this code:

$("#bib").error(function(){
   //nothing now 
});

I am wondering why I get this error:

Uncaught TypeError: $(...).error is not a function
at app.js:53
(anonymous) @ app.js:53

As you see I have shortened the code to isolate the problem but you get the whole idea. At the moment these jquery sources are included inside the page:

https://code.jquery.com/jquery-3.1.0.min.js https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js

Any idea why this happens?

like image 582
user7432810 Avatar asked Mar 10 '17 15:03

user7432810


People also ask

Is not a function error in jQuery?

on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.

What is uncaught type error?

Educative Answers Team. According to the Mozilla website for developer documents, “the TypeError object represents an error when a value is not of the expected type.” Uncaught means that the error was not caught in the catch part of the try-catch block.

Is not a function in JavaScript?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.


2 Answers

Use this instead (as stated earlier, .error has been removed).

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>

$("#bib").on('error', function(){
   //nothing now 
});

</script>
like image 99
Neil Avatar answered Sep 28 '22 05:09

Neil


From the jquery upgrade guide at: https://jquery.com/upgrade-guide/3.0/#breaking-change-load-unload-and-error-removed

Breaking change: .load(), .unload(), and .error() removed

These methods are shortcuts for event operations, but had several API limitations. The event .load() method conflicted with the ajax .load() method. The .error() method could not be used with window.onerror because of the way the DOM method is defined. If you need to attach events by these names, use the .on() method, e.g. change $("img").load(fn) to $("img").on("load", fn).

like image 36
freedomn-m Avatar answered Sep 28 '22 05:09

freedomn-m