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
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.