Open In App

HTML | DOM Track src property

The DOM track src property is used to set or return the value of the src attribute which shows the URL of the text track

Syntax:

It is used to return the Track src property.

trackObject.src

It is also used to set the Track src property.

trackObject.src = URL

Value:

Return Value: It returns the URL(including protocol) of the track in the form of string. 

Example: 




<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            text-align: center;
        }
 
        h1 {
            color: green;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>
        Track src Property
    </h2>
    <video width="100" height="100" controls>
        <track src=
            kind="subtitles" srclang="en"
            label="English">
        <source id="myTrack" src=
            type="video/mp4">
    </video>
     
<p>
        Click the button to get
        the source of the track.
    </p>
 
    <button onclick="myFunction()">
        Get URL
    </button>
    <p id="gfg"></p>
 
 
    <!-- Script to get the Track src property -->
    <script>
        function myFunction() {
            var x = document.getElementById(
                "myTrack");
            document.getElementById(
                "gfg").innerHTML = myTrack.src;
        }
    </script>
</body>
</html>

Output

 Before clicking on the button:

 

After clicking on the button: 

  

Supported Browsers:


Article Tags :