Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

HTML onerror Event Attribute

❮ HTML Event Attributes

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

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

Related Pages

HTML DOM reference: onerror event


❮ HTML Event Attributes