Javascript DOM HTML Video load() Method

Introduction

Change the video source and re-load the video:

Click the button to change the video source and re-load the video.

View in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" controls autoplay>
  <source id="mp4_src" src="video.mp4" type="video/mp4">
  <source id="ogg_src"  src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>//from   ww  w  .ja  v a2  s. c  o m
<button onclick="myFunction()">Test</button>

<script>
function myFunction()  {
  document.getElementById("mp4_src").src = "video.mp4";
  document.getElementById("ogg_src").src = "video.ogg";
  document.getElementById("myVideo").load();
}
</script>
</body>
</html>

The load() method re-loads the video element.

The load() method is used to update the video element after changing the source or other settings.

Syntax
element.load();



PreviousNext

Related