Option selected attribute

Definition and Usage

selected Set or return the selected state of the option.

See also:

HTML Reference Manual:HTML <option> selected Attribute

HTML Reference Manual:HTML <option> Tag

Example

Example 1

Change the selected option in the dropdown list to "orange":

document.getElementById("orange").selected = true;

Try it yourself

Example 2

Check if the "banana" option in the dropdown list is selected:

var x = document.getElementById("banana").selected;

Try it yourself

Syntax

Return the selected attribute:

optionObject.selected

Set the selected attribute:

optionObject.selected = true|false

Attribute Value

Value Description
true|false

Specifies whether the option in the drop-down list should be selected.

  • true - The option is selected
  • false - Default. The option is not selected

Technical Details

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

Browser Support

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