HTML DOM
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, thetextproperty can still be used to set the content, but it will have no visible effect.
Value
A string.
Example
const optionElement = document.getElementById("exampleOption");
console.log(`Text property: ${optionElement.text}`);
optionElement.text = "Updated text";
Specifications
Browser compatibility
See also
- select
- datalist
- optgroup
- HTMLOptionElement.value
- HTMLOptionElement.label
- HTMLScriptElement.text
- HTMLAnchorElement.text
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
