• Register
+1 vote
122 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'.
by (6.9k points)  

1 Answer

0 votes

Solution :

Your function must be returning a string rather than the div node. And appendChild can only append a node.

e.g., if you try to appendChild to the string:

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

The above code will give error. 

Following code will work:

var z = document.createElement('p'); // is a node
z.innerHTML = 'test satu dua tiga';
document.body.appendChild(z);
by (36.1k points)  
...