JSFiddle - React, Tailwind, and code Playground
by Paul Leech
HTML
<ul id="list">
<li id="element1">One</li>
<li id="element2">Two</li>
<li id="element3">Three</li>
</ul>
<div class="btn" onClick="addAnother()"> Add Eelement </div>
CSS
.btn {
width: 100px;
height: 25px;
background: red;
color: white;
text-align: center;
line-height: 25px;
}
ul#list {
list-style: none;
width: 400px;
}
ul#list > li {
width: 100%;
height: 20px;
background: green;
margin-bottom: 3px;
color: white;
text-align: center;
line-height: 20px;
}
JavaScript
addAnother = function() {
var ul = document.getElementById("list");
var li = document.createElement("li");
var children = ul.children.length + 1
li.setAttribute("id", "element"+children)
li.appendChild(document.createTextNode("Four "+children));
ul.appendChild(li)
}