Advertisement
Home Open Editor ❯

HTML onerror Attribute

Example

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

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

Try this code ❯

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">


Applies to:

The onerror attribute can be used on the following element:


Advertisement

Attribute Values

Value Description
script Specifies the script to be run on onerror
Home Open Editor ❯
Advertisement