Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The firstChild Property</h2> <p>Click the button to get the text of the first child node of the select element.</p> <p><button onclick="myFunction()">Try it</button></p> <select id="mySelect" size="4"><option>Audi</option><option>BMW</option><option>Saab</option><option>Volvo</option></select> <p id="demo"></p> <script> function myFunction() { let text = document.getElementById("mySelect").firstChild.text; document.getElementById("demo").innerHTML = text; } </script> </body> </html>