JSFiddle - React, Tailwind, and code Playground

by Lalji Tadhani

HTML

<ul id="list">

</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;
}
li{
  display: inline-block;
  background: #E43;
  color: white;
  padding: 10px 20px 10px 20px;
}
li:hover{
  background: #F65;
  border-bottom: 2px solid dodgerblue;
}

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("Element "+children));
    ul.appendChild(li)
}