HTML DOM Option selected Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

Option selected Property

❮ Option Object

Example

Change the selected option in a drop-down list to "orange":

document.getElementById("orange").selected = true;
Try it Yourself »

Definition and Usage

The selected property sets or returns the selected state of an option.


Browser Support

Property
selected Yes Yes Yes Yes Yes

Syntax

Return the selected property:

optionObject.selected

Set the selected property:

optionObject.selected = true|false

Property Values

Value Description
true|false Specifies whether an option in a drop-down list should be selected or not.
  • true - The option is selected
  • false - Default. The option is not selected

Technical Details

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

More Examples

Example

Find out if the "banana" option in a drop-down list is selected or not:

var x = document.getElementById("banana").selected;
Try it Yourself »

Related Pages

HTML reference: HTML <option> selected attribute


❮ Option Object