HTML | DOM Option text Property
The Option text property in HTML DOM is used to set or return the text of an <option> element. The text value sent to the server when user submitted the form.
Syntax:
- It is used to return the Option text Property.
optionObject.text
- It is used to set the Option text Property.
optionObject.text = text
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
- HTML | DOM Option value Property
- HTML | DOM Option label Property
- HTML | DOM option index Property
- HTML | DOM Option disabled Property
- HTML | DOM Option selected Property
- HTML | DOM Option form Property
- HTML | DOM Option defaultSelected Property
- How to get text of specific option tag using jQuery?
- HTML | DOM Anchor Text Property
- HTML | DOM Script text Property
- HTML | DOM Input Text value Property
- HTML | DOM Input Text name Property
- HTML | DOM Title text Property
- HTML | DOM Input Text maxLength Property
- HTML | DOM Input Text autocomplete Property
Property Values: It contains single value text which defines the text content of an <option> element.
Return Value: It returns a string value which represent the text content of the option element.
Example 1: This Example illustrate how to set the Option text Property.
<!DOCTYPE html> <html> <head> <title> HTML DOM Option text Property </title> </head> <body style = "text-align: center;"> <h1 style = "color: green;"> GeeksforGeeks </h1> <h2>DOM Option text Property</h2> <!-- List of Options --> <select> <option id="GFG">Merge Sort</option> <option id="geeks">Bubble Sort</option> <option id="user">Insertion Sort</option> <option id="java">Quick Sort</option> </select> <br><br> <button onclick="myGeeks()"> Submit </button> <!-- script to set option text --> <script> function myGeeks() { var x = document.getElementById("GFG").text = "Heap Sort"; } </script> </body> </html> |
Output:
before Click on the Button:

After Click on the Button:

Example 2: This Example illustrate how to return the Option text Property.
<!DOCTYPE html> <html> <head> <title> HTML DOM Option text Property </title> </head> <body style = "text-align: center;"> <h1 style = "color: green;"> GeeksforGeeks </h1> <h2>DOM Option text Property</h2> <!-- List of Options --> <select onchange="myGeeks(this)"> <option id="GFG">Merge Sort</option> <option id="geeks">Bubble Sort</option> <option id="user">Insertion Sort</option> <option id="java">Quick Sort</option> </select> <br><br> <p id="sudo" style="font-size:20px;color:green;"></p> <!-- script to return Option text --> <script> function myGeeks(selTag) { var x = selTag.options[selTag.selectedIndex].text; document.getElementById("sudo").innerHTML = "The Selected Option is : " + x; } </script> </body> </html> |
Output:
Before Selecting an Option:

After Selecting an Option”

Supported Browsers: The browser supported by DOM Option text Property are listed below:
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



