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

Javascript examples for DOM Event:addEventListener

Description

The onplay event occurs when the audio/video has been started or is no longer paused.

Summary

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Press play.</p>

<video controls id="myVideo">
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>/*from   ww  w . j a v  a2s .  c  o  m*/

<script>
document.getElementById("myVideo").addEventListener("play", myFunction);

function myFunction() {
    console.log("The video has started to play");
}
</script>

</body>
</html>

Related Tutorials