Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onended Event</h2>
<p>Use the HTML DOM to assign an "onended" event to an audio element.</p>
<p>Press play and wait for the audio to end.</p>
<audio id="myAudio" controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
<p id="demo"></p>
<script>
document.getElementById("myAudio").onended = function() {myFunction()};
function myFunction() {
  document.getElementById("demo").innerHTML = "The audio has ended.";
}
</script>
</body>
</html>