Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML | DOM Track srclang property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The DOM track srclang property is used to set or return the value of the srclang attribute which shows the language of the text track.

Note: srclang attribute is required with kind = “subtitles”

Syntax:

  • It is used to return the Track srclang property.
    trackObject.srclang
  • It is also used to set the Track srclang property.
    trackObject.srclang = language_code

Value:

  • language_code: It is used to specify the language of the text track. It is a two-letter code.

Return Value: It returns language code of the track in the form of string.

Example:




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

Output:
Before clicking on the button:

After clicking on the button:

Supported Browsers:

  • Google Chrome
  • Internet Explorer 10.0+
  • Opera

My Personal Notes arrow_drop_up
Last Updated : 21 Mar, 2022
Like Article
Save Article
Similar Reads
Related Tutorials