Option defaultSelected attribute

Definition and Usage

defaultSelected attribute returns selected attribute the default value.

If the default selected option is returned, this property returns true, otherwise return false.

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

See also:

HTML Reference Manual:HTML <option> Tag

Example

Check if the selected option is selected 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

Syntax

optionObject.defaultSelected

Technical Details

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

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support