html tutorial - onerror Attribute in HTML - html5 - html code - html form



  • The onerror attribute happens when an error has been shown during the loading of a file.
  • The onerror attribute is a section of the Event Attributes.

Syntax for onerror attribute in HTML:

<element onerror="script">

Applies To:

Element Attribute
<audio> onerror
<body> onerror
<embed> onerror
<img> onerror
<object> onerror
<script> onerror
<style> onerror
<video> onerror

Attribute Values:

Value Description
script The script can run onerror

Sample Coding for onerror Attribute in HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>Wikitechy onerror attribute</title>
    </head>
    <body>
        <video width="320" height="240" controls onerror="onError()">
        <source src="hibiscus.mp4" type="video/mp4">
        </video>
        <script>
        function onError() 
        {
          alert("Wikitechy video could not be loaded");
        }
        </script>
    </body>
</html>

Code Explanation for onerror Attribute in HTML:

onerror Attribute Code Explanation

  1. <video> tag is used to display the video with controls.
  2. The onerror attribute is used to call onError() JavaScript function if any error occurs during the file loading.
  3. The JavaScript function onError is used to display an alert message.

Browser Support for onerror Attribute in HTML:

Yes Yes Yes Yes Yes

Related Searches to onerror attribute in html