Script breaks with this code
Closed this issue · 3 comments
<script>
--
| 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");
| var nodeCopy = document.getElementById(data).cloneNode(true);
| //nodeCopy.id = "newId"; // If this line uncommented, it does not work on desktop but if commented out this works on desktop. neither work on mobile.
| nodeCopy.setAttribute('draggable', false);
| nodeCopy.setAttribute('height','2px');
| ev.target.appendChild(nodeCopy);
|
| }
| </script>
Did you try using setAttribute instead of setting the id directly?
nodeCopy.setAttribute("id", "newId");
I believe cloneNode returns an object that implements the Node interface, which does not include the id property.
If that is indeed the problem, the setAttribute method will solve it.
Did you try using setAttribute instead of setting the id directly?
nodeCopy.setAttribute("id", "newId");
I believe cloneNode returns an object that implements the Node interface, which does not include the id property.
If that is indeed the problem, the setAttribute method will solve it.
This tip fixes issue on desktop, but touchscreen mode still does not work for the drop feature. Drag works now
I'm closing this mostly because of how much time has passed and how much the code has changed since this issue was filed. If this is still a concern, please file a new issue. I recently signed on to this project and would like to make sure we're covering all the bases, while also making sure there are no lingering issues based on old code.