Skip to content
Related Articles

Related Articles

HTML | DOM Option defaultSelected Property

View Discussion
Improve Article
Save Article
  • Last Updated : 26 May, 2022

The DOM Option defaultSelected Property is used to return the default value of a selected attribute. The selected attribute in HTML is used to specify which option should be by default selected when the page loads. This is a boolean attribute. The option that is having the selected attribute will be displayed by default.

Note: If an option is selected by default, it is displayed first in the drop-down list.


  • It is used to return the Property.

Return Value: It returns a Boolean value which represents that the option is selected by default or not.
Example: This Example illustrate how to return the defaultSelected property.  


<!DOCTYPE html>
        <title>DOM option defaultSelected Property</title>
    <body style = "text-align: center;">
        <h1 style = "color: green;">GeeksforGeeks</h1>
        <h2>DOM defaultSelected Property</h2>
        <!-- List of Options -->
        <select id="GFG">
            <option value="merge">Merge Sort</option>
            <option value="bubble">Bubble Sort</option>
            <option value="insertion">Insertion Sort</option>
            <!-- Option element with selected attribute -->
            <option value="quick" selected>Quick Sort</option>
     <button onclick="myGeeks()">Submit</button>
     <p id="sudo" style="font-size:20px;color:green;"></p>
        function myGeeks() {
       var x = document.getElementById("GFG").selectedIndex;
       var y = document.getElementsByTagName("option");
       document.getElementById("sudo").innerHTML =
                       "Is " + y[x].text + " selected by default? "
                      + "<br>" + "yes It's " + y[x].defaultSelected;

Before Clicking On Button: 

After Clicking On Button: 

Supported Browsers: The browser supported by DOM Option defaultSelected Property are listed below: 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!