Javascript DOM HTML Audio src Property get

Introduction

Get the URL of an audio file:

var x = document.getElementById("myAudio").src;

Click the button to get the URL of the audio.

View in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls src="sound.ogg"></audio>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//  w ww . jav  a2  s.co  m
  var x = document.getElementById("myAudio").src;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The src property sets or gets the src attribute of an <audio>.

The src attribute sets the URL of the audio file.




PreviousNext

Related