Audio src Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The src property sets or gets the value of the src attribute of an audio, which identifies the location (URL) of the audio file.

Set the src property with the following Values

Value Description
URL Sets the URL of the audio file.

Possible values:

  • An absolute URL - like src="http://www.example.com/movie.ogg"
  • A relative URL - like src="movie.ogg"

Return Value

A String, representing the URL of the audio file.

The following code shows how to get the URL of an audio file:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls src="your.ogg">
</audio>/*from   w w  w  .  j  av a 2s.  c  om*/

<button onclick="myFunction()">get the URL of the audio</button>

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

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

</body>
</html>

Related Tutorials