Skip to content Skip to sidebar Skip to footer

Appendto() And Append() Works, Appendchild() Does Not

As part of a drag-and-drop file upload interface, showImage is called when a file is dropped on the target container. showImage checks that the file is an image, reads the file, cr

Solution 1:

querySelectorAll() returns a node list. To get the first element, access it by index:

var dropTarg = document.querySelectorAll('.drop-container')[0];
dropTarg.appendChild(newImg);

Some error handling to make sure it found something would probably be in order.

Solution 2:

querySelectorAll()

always returns live Node List which is array-like , so you have to use either .each() or a for loop , or specify the index of the element you are targetting.

Post a Comment for "Appendto() And Append() Works, Appendchild() Does Not"