HTMLOptionElement: text property

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{ApiRef("HTML DOM")}}

The **text** property of the {{domxref("HTMLOptionElement")}} represents the text inside the {{htmlelement("option")}} element. This property represents the same information as {{domxref("Node.textContent")}}.

توجه: If the element has a label, the text inside the {{htmlelement("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

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{HTMLElement("select")}}
  • {{HTMLElement("datalist")}}
  • {{HTMLElement("optgroup")}}
  • {{domxref("HTMLOptionElement.value")}}
  • {{domxref("HTMLOptionElement.label")}}
  • {{domxref("HTMLScriptElement.text")}}
  • {{domxref("HTMLAnchorElement.text")}}