We can create an <ol> element via the document.createElement()
method:
var x = document.createElement("OL");
Click the button to create an OL element and a LI element.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j a va2s . com var x = document.createElement("OL"); x.setAttribute("id", "myOl"); document.body.appendChild(x); var y = document.createElement("LI"); var t = document.createTextNode("CSS"); y.appendChild(t); document.getElementById("myOl").appendChild(y); } </script> </body> </html>