Create an Ol Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Ol

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create an OL element and a LI element</button>

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

<script>
function myFunction() {// w  w w  .j a v  a  2 s  . co  m
    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>

Related Tutorials