Javascript DOM HTML Video src Property set

Introduction

Change the URL of a video:

document.getElementById("myVideo").src = "video.ogg";

Click the button to change the URL of the video.

View in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" controls src="video.ogg">
  Your browser does not support the video tag.
</video>//from  ww  w.  j av  a2 s. com
<button onclick="myFunction()">Test</button>

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

<script>
var x = document.getElementById("myVideo");

function myFunction() {
  isSupp = x.canPlayType("video/mp4");
  if (isSupp == "") {
    x.src = "video.ogg";
  } else {
    x.src = "video.mp4";
  }
  x.load();

  document.getElementById("demo").innerHTML = "Video";
}
</script>

</body>
</html>

The src property sets or gets the value of the src attribute of a video.

The src attribute specifies the location URL of the video file.




PreviousNext

Related