The issue is best demonstrated with the W3School example (https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_ondrag_all).
The code demonstrates a drag drop example. The "Drag me!" text in the left box can be dragged to the right and the left box. When over a drop target the box gets a red dotted frame. When outside the box the frame disappears. Unfortunately, the frame also disappears when dragged over a child element within that box although the text can be correctly dropped there.
My solution, however, doesn't work either.
// When the draggable p element enters the droptarget, change the DIVS's border style
document.addEventListener("dragenter", function(event) {
if (( event.target.className == "droptarget" )||(event.target.parentNode.className == "droptarget" )) {
if ( event.target.className == "droptarget" ){
event.target.style.border = "3px dotted red";
}else{
event.target.parentNode.style.border = "3px dotted red";
}
}
});
// When the draggable p element leaves the droptarget, reset the DIVS's border style
document.addEventListener("dragleave", function(event) {
if (( event.target.className == "droptarget" )||(event.target.parentNode.className == "droptarget" )) {
if ( event.target.className == "droptarget" ){
event.target.style.border = "";
}else{
event.target.parentNode.style.border = "";
}
}
});