gaurav jain
gaurav jain

Reputation: 1345

Change HTML5 video tag width and height through Javascript

I have the following code in client side JS:

$(function() {
  $("#player1").html(
    '<video width=' + width + ' height=' + height + ' autoplay>' +
      '<source src=' + curPlayListHrefs[0] + ' type="video/youtube"></source>' +
    '</video>'
  );
});

I tried:

  var video = document.getElementsByTagName("video")[0];
  video.videoHeight = 300;
  video.videoWidth = 700;

Is it possible for me to change the width/height of the video tag?

Upvotes: 5

Views: 25590

Answers (1)

Musa
Musa

Reputation: 97672

Try setting its width and height attributes

var video = document.getElementsByTagName("video")[0];
video.setAttribute('height', '300');
video.setAttribute('width', '700');

or setting its width and height properties

var video = document.getElementsByTagName("video")[0];
video.height = 300;
video.width = 700;

Upvotes: 8

Related Questions