• Register
0 votes
875 views

Problem :

I want to drag and drop the image on the div. The image does not get dragged onto a div and gives the below error :

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.draganddrop.html:20 dropdraganddrop.html:26 ondrop

 

7 5 2
3,870 points

1 Answer

0 votes

Solution :

It has actually a very simple answer.

The function is returning the string rather than a div node. appendChild can only append the node.

So for example, if you try to do just appendChild the string:

var s = '<p>test satu dua tiga</p>'; // is the string 
document.body.appendChild(s);

This above code will never work. What will work is as below:

var s = document.createElement('p'); // is the node
s.innerHTML = 'test satu dua tiga';
document.body.appendChild(s);

 

OR

This will happen if you accidentally are not dragging a element that does have the id assigned (example you are dragging a surrounding element). In that case an ID is empty and your function drag() is assigning an empty value which is then passed to the drop() and it fails there.

So you should try assigning the ids to all of your elements, including your tds, divs, or whatever is around the draggable element.

Hope above solutions will fix your issue.

9 7 4
38,600 points

Related questions

1 vote
1 answer 319 views
319 views
Problem : Trying to drag and drop an image on a div. but the image does not get dragged on to the div and gives the following error: uncaught typeerror: failed to execute 'appendchild' on 'node': parameter 1 is not of type 'node'.
asked Nov 11, 2019 peterlaw 6.9k points
0 votes
1 answer 771 views
771 views
Problem : Facing following javascript issue failed to execute 'removechild' on 'node': the node to be removed is not a child of this node.
asked Nov 14, 2019 peterlaw 6.9k points
0 votes
1 answer 254 views
254 views
Problem : I am unable to solve my link problem. Can anybody help on to this to link the CSS and JS File? I am facing below error : Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/RetailSmart/jsp/ ... .js Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/RetailSmart/jsp/Jquery/prettify.js
asked Jan 10 alecxe 7.5k points
0 votes
1 answer 197 views
197 views
Problem : I want to save my canvas to a img. I have this function: function save() { document.getElementById("canvasimg").style.border = "2px solid"; var dataURL = canvas.toDataURL(); document.getElementById("canvasimg").src = dataURL; document. ... error: Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. What should I do?
asked Nov 21, 2019 peterlaw 6.9k points
0 votes
1 answer 84 views
84 views
Problem : I have the javascript application and when I try to run it on firefox I am facing the below error on the console: &ldquo;Because its mime type ('text/html') is not a supported stylesheet mime type&rdquo; Now I am completely confused because of this error. Kindly somebody let me know how can I resolve my above error?
asked Jan 29 jwilliam 3.9k points