Open In App

HTML | DOM Track default property

Improve
Improve
Like Article
Like
Save
Share
Report

The DOM track default property is used to set or return the default state of the track. It reflects thedefault attribute.

Note: With a default attribute, there must not be more than one track element per media element.

Syntax:

  • It is used to return the default property.
    trackObject.default
  • It is also used to set the default property.
    trackObject.default = true|false

Value: It is either true or false which shows the default state of the track. By default, it is false.

  • true: If the preferences of user do not indicate that another track would be more appropriate then track is to be enabled.
  • false: If the preferences of user do not indicate that another track would be more appropriate then track is not to be enabled. It is a default value.

Return Value: It returns the default state of the track in the form of boolean value.




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


Output:
Before clicking on the button:

After clicking on the button:

Supported Browsers:

  • Google Chrome
  • Internet Explorer 10.0+
  • Opera


Last Updated : 21 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads