Javascript examples for DOM HTML Element:Option
The text property sets or gets the text of an option element.
Set the text property with the following Values
Value | Description |
---|---|
text | Sets the text of the option element |
A String, representing the text of the option element
The following code shows how to change the text of an option element in a drop-down list:
<!DOCTYPE html> <html> <body> Select your favorite fruit: <select> <option id="a">Apple</option> <option id="orange">Orange</option> <option id="pineapple">Pineapple</option> <option id="banana">Banana</option> </select>/*w ww. ja va 2 s. c om*/ <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("a").text = "newTextForApple"; } </script> </body> </html>