HTMLOptionElement: text property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The text
property of the HTMLOptionElement
represents the text inside the <option>
element.
This property represents the same information as Node.textContent
.
Note:
If the element has a label
, the text inside the <option>
is not visually rendered. In this case, the text
property can still be used to set the content, but it will have no visible effect.
Value
A string.
Example
js
const optionElement = document.getElementById("exampleOption");
console.log(`Text property: ${optionElement.text}`);
optionElement.text = "Updated text";
Specifications
Specification |
---|
HTML # dom-option-text-dev |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
text |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.