HTML onerror Event Attribute
Example
Execute a JavaScript if an error occurs when loading an image:
<img src="image.gif" onerror="myFunction()">
Try it yourself »
Definition and Usage
The onerror attribute fires when an error occurs while loading an external file (e.g. a document or an image).
Browser Support
Event Attribute | |||||
---|---|---|---|---|---|
onerror | Yes | Yes | Yes | Yes | Yes |
Differences Between HTML 4.01 and HTML5
None.
Syntax
<element onerror="script">
Attribute Values
Value | Description |
---|---|
script | The script to be run on onerror |
Technical Details
Supported HTML tags: | <img>, <input type="image">, <object>, <script> and <style> |
---|
Related Pages
HTML DOM reference: onerror event
HTML Event Attributes