Get Option Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option


The Option object represents an HTML <option> element.

You can access an <option> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

  <option id="myOption" value="css">CSS</option>
  <option value="java">Java</option>
</select>//w  w w .j a v  a  2s  .  c  o  m

<button onclick="myFunction()">get the text of the option in the drop-down list</button>

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

function myFunction() {
    var x = document.getElementById("myOption").text;
    document.getElementById("demo").innerHTML = x;


Related Tutorials