Edit This Code:
<!DOCTYPE html>
<html>
<body>

<p>Click the button to get the text of the third child element (index 2) of the select element.</p>

<select id="mySelect" size="4">
  <option>Audi</option>
  <option>BMW</option>
  <option>Saab</option>
  <option>Volvo</option>
</select>
<br><br>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var c = document.getElementById("mySelect").children;
    document.getElementById("demo").innerHTML = c[2].text;
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy