JSFiddle - React, Tailwind, and code Playground

by Charlotte Jhao

HTML

<body>
  <!-- add new item Dynamically in the show block -->
  <div id="showBlock"></div> 
  <!-- click the button to add new item -->
  <input type="button" id="btn" value="addItem"/>
</body>

JavaScript

var txtId = 1;
//add input block in showBlock
$("#btn").click(function () {
    $("#showBlock").append('<div id="id'+txtId+'">Input:<input type="text" name="test[]" /> <input type="button" value="del" onclick="deltxt('+txtId+')"></div>');
    txtId++;
});

//remove div
function deltxt(id) {
    $("#id"+id).remove();
}