Open In App

HTML onended Event Attribute

Last Updated : 07 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML onended Attribute is a event attribute which works when the audio/video is ended. We can add some custom message in this event like “Thank for watching”, “Share”, etc. 

Usage: This attribute is used in <audio> and <video> element.

Syntax:

<element onended="myScript">
  • Attribute Value: This attribute contains single value script which works when onended event attribute call.

Example:

HTML




<!DOCTYPE html>
<html>
<body>
    <center>
        <h1 style="color:green">GeeksforGeeks</h1>
        <h2>HTML onended Event Attribute</h2>
        <audio controls onended="gfgFun()">
            <source src="beep.mp3" type="audio/mpeg">
        </audio>
 
        <script>
            function gfgFun() {
                alert("Thanks for listning");
            }
        </script>
    </center>
</body>
</html>


Output:

 

Supported Browsers:

  • Google Chrome 3
  • Edge 12
  • Internet Explorer 9
  • Firefox 3.5
  • Apple Safari 3.1
  • Opera 10.5

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads