Create a Li Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Li

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<ol id="myList">
  <li>SQL</li>
  <li>HTML</li>
  <li>XML</li>
</ol>//  w  w  w .ja v a  2s . c  om

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

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

<script>
function myFunction() {
    var x = document.createElement("LI");
    var t = document.createTextNode("CSS");
    x.appendChild(t);
    document.getElementById("myList").appendChild(x);
}
</script>

</body>
</html>

Related Tutorials