Source src Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Source

Description

The src property sets or gets the value of the src attribute in a <source> element, which identifies the URL of the media file to play.

Set the src property with the following Values

Value Description
URL Sets the URL of the media file.

Return Value

A String, representing the URL of the media file.

The following code shows how to return the URL of a media file:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio controls>
  <source id="mySource" src="your.mp3" type="audio/mpeg">
  <source src="your.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>/*  ww w .  j ava 2  s  .com*/

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

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
    var x = document.getElementById("mySource").src;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials