Actually i have scenario like, i have four divs & i should able to swap the div squares ,means i can interchange the position of div with each other without any error.while doing so mycode is not working when i am generating the divs dynamically.if manually i am creating four div then the code is somewhat working.i have attached the stackblitz link. could some one please help me to fix this issue..
please go through this link > https://stackblitz.com/edit/angular-srvwgw
@HostListener('drop', ['$event'])
onDrop(event) { event.preventDefault();
var data = event.dataTransfer.getData("text");
// event.dataTransfer.dropEffect = 'copy';
var div = document.getElementById(data);
var mynode = document.getElementById(event.target.id);
var clonedElement1 = div.cloneNode(true);
var clonedElement2 = mynode.cloneNode(true);
mynode.parentNode.replaceChild(clonedElement1, mynode);
div.parentNode.replaceChild(clonedElement2, div);
}
i should able to swap the position of div with each other div.