Open In App

HTML | DOM Audio src Property

The DOM Audio src property is used to set or return the value of the src attribute of audio. The src attribute is generally used to specify the location (URL) of the audio file.

Syntax:



Property Values:

Possible Values:-

  1. Absolute URL: I t points to another webpage.
  2. Relative URL: It points to other files of the same web page.

Return Value: The Audio src property returns a string, which represents the URL of the Audio file. The src property returns the entire URL, including the protocol.



Example:




<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1 style="color:green">GeeksforGeeks</h1>
        <h2>HTML DOM Audio src Property</h2>
  
        <button onclick="my_Audio()" type="button">
            Change Audio
        </button>
        <br>
  
        <audio id="myAudio" controls autoplay>
            <source id="mp4_src" src=
                    type="audio/mp3">
  
            <source id="ogg_src" src=
                    type="audio/ogg">
        </audio>
  
        <script>
            function my_Audio() {
                document.getElementById("ogg_src").src = 
  
                document.getElementById("mp4_src").src =
  
                document.getElementById("myAudio").load();
            }
        </script>
    </center>
</body>
  
</html>

Output:

Supported Browser: The browser supported by HTML DOM Audio src Property are listed below:


Article Tags :