Javascript DOM HTML Video width Property get

Introduction

Get the width of a video:

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

Click the button to return the value of the width attribute of the video.

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>//  ww w. j  a  va2 s. c  o  m
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related