jQuery error() Method
jQuery error() method triggers the error event. The jQuery error event occurs when the selected element occur an error. And when the error event occurs, specified function will execute.
The error() method was deprecated in jQuery 1.8. and removed om jQuery 3.0.
Syntax
This syntax represent to the error event trigger
$(selector).error(); // This syntax does not accept any arguments.
and this syntax represent to attach a function in the error method
$(selector).error(function);
Parameter | Type | Description |
---|---|---|
function | Function | Optional. Specifies the function to execute when the click event is occurs. |
Examples
This example represent the error event trigger on the selected elements.
$(document).ready(function(){
$("img").error(function(){
$("img").replaceWith("Error while loading an image.");
});
$("button").click(function(){
$("img").error();
});
});
This example represent to attach a function to the error event.
$(document).ready(function(){
$("img").error(function(){
$("img").replaceWith("Error while loading an image.");
});
});