Advertisement
Home Open Editor ❯

HTML Audio/Video DOM src Property

Example

var vid = document.getElementById("myVideo");

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

Try this code ❯

Meaning

The src property sets or returns the current source of the audio/video.

Return a String, representing the URL of the audio/video file.

Returns the entire URL, including the protocol (like http://).


Standard Syntax

Return the src property:

audio|video.src

Set the src property:

audio|video.src="URL"


Advertisement

Property Value

Type Description
url

Value can be

  • An absolute URL - navigate to within or another web site ( href="http://www.example.com/index.html")
  • A relative URL - navigate to within a web site ( href="index.html")
Home Open Editor ❯
Advertisement