JSFiddle - React, Tailwind, and code Playground

by der_robert

HTML

<form id="irgendwas" method="POST">
    <label id="label_1"><input type="text" id="eingabe_1" name="eingabe[]" value="1"></label>
    <hr>
    <a id="neu">neu</a>
</form>

CSS

label{
    display: block;
}

JavaScript

$(document).delegate("#neu","click",function(){
var counter = 1;
    var input = $("#label_1").html();
    var counter = 1 + $("label").length;
    input = input.replace(/1/g, counter); 
    $("hr").before('<label id="label_'+counter+'">'+input+'<a id="loeschen_'+counter+'">löschen</a></label>');
});

$(document).delegate("[id^='loeschen_']","click",function(){
    var id = $(this).attr("id");
    id = id.split("_");
    $("label#label_"+id[1]).remove();
    console.log(id[1]);
});