Latest web development tutorials
 

HTML onerror Attribute


Definition and Usage

The error event occurs when an error occurred during the loading of a media file.


Applies to

The onerror attribute is part of the Event Attributes, and can be used on the following elements:

Elements Event
<audio> onerror
<body> onerror
<embed> onerror
<img> onerror
<object> onerror
<script> onerror
<style> onerror
<video> onerror

Examples

Audio Example

Run "myFunction" if an error occures during loading:

<audio onerror="myFunction()">

Video Example

Run "myFunction" if an error occures during loading:

<video onerror="myFunction()">


Browser Support

The ondurationchange attribute has the following browser support for each element:

Element
audio Yes 9.0 Yes Yes Yes
body Yes Yes Yes Yes Yes
embed Yes Yes Yes Yes Yes
img Yes Yes Yes Yes Yes
object Yes Yes Yes Yes Yes
script Yes Yes Yes Yes Yes
style Yes Yes Yes Yes Yes
video Yes 9.0 Yes Yes Yes