Javascript Reference - HTML DOM Source Object

The Source object represents an HTML <source> element.


We can access a <source> element by using getElementById().

<!DOCTYPE html>
<audio controls>
  <source id="mySource" src="" type="audio/mpeg">
  <source src="horse.ogg" type="audio/ogg">
</audio><!--from   ww  w .j  av a  2 s  . c  o m-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("mySource").src;
    document.getElementById("demo").innerHTML = x;


The code above is rendered as follows:

Source Object Properties

Property Description
media Sets or gets the media attribute in a <source> element
src Sets or gets the src attribute in a <source> element
type Sets or gets the type attribute in a <source> element

Standard Properties and Events

The Source object supports the standard properties and events.