Javascript DOM HTML Video Object get

Introduction

The Video object represents an HTML <video> element.

We can access a <video> element via document.getElementById():

var x = document.getElementById("myVideo");

Click the button to get the duration of the video, in seconds.

View in separate window

<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="100" height="100" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>/*from ww  w  .  jav a  2s. co  m*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myVideo").duration;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related