Open In App

HTML onended Event Attribute

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

Example:






<!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:

Article Tags :