Get Source Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Source

Introduction

The Source object represents an HTML <source> element.

You can access a <source> element by using getElementById():

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>//from   w w w .  ja va 2 s .  com

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

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

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

</body>
</html>

Related Tutorials