THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Option defaultSelected Property

Option Object Reference Option Object

Example

Check if the selected option is checked by default:

var x = document.getElementById("mySelect").selectedIndex;
var y = document.getElementsByTagName("option");
alert("Is " + y[x].text + " selected by default? " + y[x].defaultSelected);
Try it yourself »

Definition and Usage

The defaultSelected property returns the default value of the selected attribute.

This property returns true if an option is selected by default, otherwise it returns false.

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The defaultSelected property is supported in all major browsers.


Syntax

optionObject.defaultSelected

Technical Details

Return Value: A Boolean, returns true if the option is selected by default, otherwise it returns false

Option Object Reference Option Object