Video src Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video

Description

The src property sets or gets the src attribute of a video, which sets the location (URL) of the video file.

Set the src property with the following Values

Value Description
URL Sets the URL of the video file.

Return Value

A String, representing the URL of the video file.

The following code shows how to change the URL of a video:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" controls src="your.ogg">
  Your browser does not support the video tag.
</video>//from www .  j a va  2  s .  c  om

<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 = "your.ogg";
    } else {
        x.src = "your.mp4";
    }
    x.load();

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

</body>
</html>

Related Tutorials