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:

  • Return the src property:
    audioObject.src
  • Set the src property:
    audioObject.src = URL

Property Values:



  • URL: It is used to specify the URL of the video file.

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

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

  • Google Chrome
  • Internet Explorer
  • Edge
  • Firefox
  • Apple Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.