Black friday

Save big!

All courses under $5 - for a limited time!

Code has been added to clipboard!

How and What for Did the Deprecated jQuery .Error() Method Work

Reading time 1 min
Published Jan 11, 2018
Updated Sep 25, 2019

jQuery error: Main Tips

  • The jQuery .error() method was used to trigger an error event.
  • It also attached a listener to the error event for jQuery error handling.
  • This method was removed in the version 3.0 of jQuery.

Triggering jQuery Errors

The .error() function triggered an error event, or attached a function to run when that event happened. In the example below, see how it displayed jQuery error messages:

Example
$("img").error(() => {
    alert("Error: image could not be loaded!");
});

This was the syntax to trigger jQuery errors:

$("selector").error();

Attaching a listener for jQuery error handling looked like this:

$("selector").error(function);

Note: the jQuery .error() method was deprecated in version 1.8 and removed in 3.0.