THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Option text Property

Option Object Reference Option Object

Example

Change the text of an option element in a drop-down list:

document.getElementById("apple").text = "newTextForApple";
Try it yourself »

Definition and Usage

The text property sets or returns the text of an option element.

Tip: If the value property is not specified for an option element, then the text content will be sent to the server when the container form is submitted.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The text property is supported in all major browsers.


Syntax

Return the text property:

optionObject.text

Set the text property:

optionObject.text=text

Property Values

Value Description
text Specifies the text of the option element

Technical Details

Return Value: A String, representing the text of the option element

More Examples

Example

Return the text of the selected option in a drop-down list:

var x = selTag.options[selTag.selectedIndex].text;
Try it yourself »

Example

Get the text of all options in a drop-down list:

var x = document.getElementById("mySelect");
var txt = "All options: ";
var i;
for (i = 0; i < x.length; i++) {
    txt = txt + "\n" + x.options[i].text;
}
Try it yourself »

Option Object Reference Option Object