Element childNodes Property - Get the text of the third child node (index 2) of a <select> element: - Javascript DOM

Javascript examples for DOM:Element childNodes

Description

Element childNodes Property - Get the text of the third child node (index 2) of a <select> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<select id="mySelect" size="4">
  <option>Java</option>
  <option>SQL</option>
  <option>HTML</option>
  <option>CSS</option><
/select>
<br><br>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from  www.j a  va 2s.c  o  m*/
    var c = document.getElementById("mySelect").childNodes;
    document.getElementById("demo").innerHTML = c[2].text;
}
</script>

</body>
</html>

Related Tutorials