I am having a strange drag and drop problem in html5.
Panel A has a list of item types that you can drag and drop. Panel B is where the elements are dragged. Panel C and D are other places where you can drag and drop items, and you can drag and rearrange items between panels B, C, and D.
My problem is that I can drag an element and drop it INSIDE of another element that is inside one of the panels, which I do not want the user to be able to do. The children of these panels do not have any javascript or drag and drop properties associated with them, but they currently allow you to move elements within them.
I tried setting "ondrop =" return false; "and" ondragover = "return false;", but none of them worked.
Of course, is there a way to disable the "allow dragging into" property in an element?
Here is my code:
<div id="elem-002" draggable="true" ondragstart="drag(event)">content</div>
The main panel:
<div id="panel-b" ondrop="drop(event)" ondragover="allowDrop(event)">
<div id="elem-001" draggable="true" ondragstart="drag(event)">content</div>
</div>
JS:
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("Text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
He said another way: I can drag my "elem-002" directly into the element "elem-001", which has already been dragged. This causes an attachment of elements that I do not want to have. How can I prevent this?
source
share