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.
Syntax:
- It is used to return the Property.
optionObject.defaultSelected
Return Value: It returns a Boolean value which represent that the option is selected by default or not.
Example: This Example illustrate how to return the selected property.
<!DOCTYPE html> <html> <head> <title>DOM defaultSelected Property</title> </head> <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> </select><br><br> <button onclick="myGeeks()">Submit</button> <p id="sudo" style="font-size:20px;color:green;"></p> <script> 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; } </script> </body> </html> |
Output:
Before Clicking On Buttton:

After Clicking On Button:

Supported Browsers: The browser supported by DOM Option defaultSelected Property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM Option value Property
- HTML | DOM Option label Property
- HTML | DOM Option text Property
- HTML | DOM Option selected Property
- HTML | DOM option index Property
- HTML | DOM Option form Property
- HTML | DOM Option disabled Property
- HTML | option Tag
- HTML | option value Attribute
- HTML | DOM Option Object
- HTML | <option> label Attribute
- HTML <option> disabled Attribute
- HTML | <option> selected Attribute
- How to get the text of option tag by value using JavaScript ?
- UI vs UX Design : Which Career Option Should You Choose?
- How to get text of specific option tag using jQuery?
- How to use Checkbox inside Select Option using JavaScript ?
- How to sort option elements alphabetically using jQuery ?
- Why does AngularJS include an empty option in select ?
- HTML | DOM specified Property
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.


