Element firstElementChild Property - Get the text of the first element node of a <select> element: - Javascript DOM

Javascript examples for DOM:Element firstElementChild

Description

Element firstElementChild Property - Get the text of the first element node 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() {//  w  w  w  . ja va 2  s.co m
    var x = document.getElementById("mySelect").firstElementChild.text;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials