Javascript examples for DOM:Element lastElementChild
Element lastElementChild Property - Get the text of the last child element of a <select> element:
<!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. j a va 2s .c om*/ var x = document.getElementById("mySelect").lastElementChild.text; document.getElementById("demo").innerHTML = x; } </script> </body> </html>