Javascript DOM HTML Video width Property set

Introduction

Change the width of the video player:

document.getElementById("myVideo").width = "200";

Click the button to change the width of the video player.

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

<script>
function myFunction() {
  document.getElementById("myVideo").width = "200";
}
</script>

</body>
</html>

The width property sets or gets the width of a video.

We should set both the height and width attributes for videos.

If height and width are set, the space required for the video is reserved when the page is loaded.

The width property returns a Number representing the width of the video in pixels.




PreviousNext

Related