Error: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

前端 未结 5 1615
孤街浪徒
孤街浪徒 2020-11-27 11:57

I am trying to drag and drop an image on a div. The image does not get get dragged onto the div and gives the following error

Uncaught TypeError: Failed to e         


        
5条回答
  •  [愿得一人]
    2020-11-27 12:18

    It's actually a simple answer.

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

    For example, if you try to appendChild the string:

    var z = '

    test satu dua tiga

    '; // is a string document.body.appendChild(z);

    The above code will never work. What will work is:

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

提交回复
热议问题