Tutorials References Exercises Bootcamp Menu
Sign Up Create Website Get Certified Pro

HTML onerror Event Attribute

❮ HTML Event Attributes


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


<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>, <link>, and <script>

Related Pages

HTML DOM reference: onerror event

❮ HTML Event Attributes