Option selected Property
Example
Change the selected option in a drop-down list to "orange":
document.getElementById("orange").selected = true;
Try it Yourself »
Description
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.
|
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
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.