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
The selected property is supported in all major browsers.
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.
|
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