Hi im trying to create a form builder im approaching this by making creating elements putting them is a list group then making them draggable. This works so far however when i drag in item and place it the it disappears from the elements section this makes sense but i would like it to find the id of the item that has been selected and then copy the element but with a different id.
This is my code so far JavaScript
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
console.log("Component Selected")
var elem = document.querySelector(ev.target.id);
var clone = elem.cloneNode(true);
clone.id = ('drag9');
elem.after(clone);
}
<div class="row">
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
<ul class="list-group">
<li draggable="true" ondragstart="drag(event)" id="drag1" class="list-group-item">
<label for="exampleFormControlInput1" class="form-label">Input</label>
<button type="button" class="fa-solid fa-pen-to-square fa-lg"></button>
<input type="email" class="form-control" id="ControlInput1" placeholder="">
</li>
</ul>
</div>
</div>