HTML onerror event Attribute

❮ HTML Event Attributes

Example

<img src="dummy.png" onerror="myFunction()">

<script>
function myFunction() {
  alert("Unable to load the image.");
}
</script>

Meaning

The onerror attribute is used to capture various events generally related to communication using Ajax, though may apply to arbitrary URL loading using media elements like images, audio, and video. This attribute is also used for catching script related errors.


Standard Syntax

<element onerror="script">

Browser Support




Status







Attribute Values

Value Description
script Specifies the script to be run on onerror



Technical Details

Supported HTML elements:

<img>, <input type="image">, <object>, <link>, and <script>
❮ HTML Event Attributes