X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook