jQuery error() method
Example
If the image element encounters an error, replace it with text:
$("img").error(function(){
$("img").replaceWith("
Image load error!
");});
Try it »
Definition and Usage
The error() method wasdeprecated.
The error event occurs when an element encounters an error (when the element does not load correctly).
The error() method triggers the error event, or specifies a function to run when an error event occurs.
**Tip:** This method is a shorthand for bind('error', handler).
Syntax
Trigger the error event of the selected element:
$(
selector
).error()
Try it
Add a function to the error event:
$(
selector
).error(
function
)
Try it
| Parameters | Description |
|---|---|
| function | Optional. Specifies the function to run when the error event occurs. |
jQuery event methods