THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Option selected Property

Option Object Reference 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

Internet Explorer Firefox Opera Google Chrome Safari

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.
  • 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 Reference Option Object