addEventListener("ended", myFunction); - Javascript DOM Event

Javascript examples for DOM Event:addEventListener

Description

The onended event occurs when the audio/video has reached the end.

Summary

Bubbles No
Cancelable No
Supported HTML tags: <audio> and <video>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>//  ww w  .  ja  v a  2  s.  c o m

<p id="demo"></p>

<script>
document.getElementById("myAudio").addEventListener("ended", myFunction);

function myFunction() {
    document.getElementById("demo").innerHTML = "The audio has ended.";
}
</script>

</body>
</html>

Related Tutorials