Create an Option Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option


You can create an <option> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<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>

function myFunction() {
    var x = document.createElement("OPTION");
    x.setAttribute("value", "css");
    var t = document.createTextNode("CSS");


Related Tutorials