HTML onended Event Attribute

Description

The event attribute onended occurs when the audio/video is ended. We can add some custom message in this event like “Thank you for watching”, “Share Video”, etc.

Syntax

<element onended="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE HTML>
<html>
<body>

<audio id="myAudio" controls onended="myFunction()">  
  <source src="audio.mp3" type="audio/mpeg">
  Your browser does not support the audio tag.
</audio>

<p>Play sound file.</p> 

<script>
function myFunction() {
    alert("Thank you for listening.");
}
</script> 

<p>
This example shows how to use the onended attribute for an AUDIO element.</p>

</body>
</html>

Supported Tags

<audio> and <video>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XXYes3.5XX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYes4XXX