Javascript examples for DOM HTML Element:Option
You can create an <option> element by using the document.createElement() method:
<!DOCTYPE html> <html> <body> <select id="mySelect"> </select>/*from w w w . ja v a2 s . co m*/ <button onclick="myFunction()">create an OPTION element</button> <p id="demo"></p> <script> function myFunction() { var x = document.createElement("OPTION"); x.setAttribute("value", "css"); var t = document.createTextNode("CSS"); x.appendChild(t); document.getElementById("mySelect").appendChild(x); } </script> </body> </html>