HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Option Object : Change the text of an option element in a drop-down list
The text property sets or returns the text of an option element.
Property | |||||
---|---|---|---|---|---|
text | Yes | Yes | Yes | Yes | Yes |
Return the text property:
Set the text property:
Value | Description |
---|---|
text | Specifies the text of the option element |
Return Value: | A String, representing the text of the option element |
---|
Return the text of the selected option in a drop-down list:
var x = selTag.options[selTag.selectedIndex].text;
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;
}
❮ Option Object