Add list items using javascript
by gauravsingh
HTML
<input type="text" id="myInput">
<button onclick="myFunction()">Add</button>
<ol id="demo">
<li>first</li>
<li>second</li>
</ol>
JavaScript
function myFunction() {
var x = document.getElementById("myInput").value;
var node = document.createElement("li");
var text = document.createTextNode(x);
node.appendChild(text);
document.getElementById("demo").appendChild(node);
}