Javascript DOM onplaying Event via HTML Tag onplaying function

Introduction

In JavaScript:

object.onplaying = function(){
       myScript};

This example uses the HTML DOM to assign an "onplaying" event to a video element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Play, pause and then play the video again.</p>

<video controls id="myVideo">
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>// ww w  .ja v  a 2 s.  c o  m

<p id="demo"></p>
<script>
document.getElementById("myVideo").onplaying = function() {myFunction()};

function myFunction() {
  document.getElementById("demo").innerHTML = "The video is now playing";
}
</script>

</body>
</html>
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>



PreviousNext

Related