I am trying to clone a node that is a child of another node, however js is not letting me index the HTMLCollection/NodeList datatype. Whenever I try to index that datatype it always results in an undefined value. Even when I convert that datatype to an array as per Most efficient way to convert an HTMLCollection to an Array I am still not able to index the array.
var viewports = document.getElementsByClassName('imageViewerViewport');
console.log(viewports[0].childNodes) // In the console shows the children I expect to see
console.log(viewports[0].childNodes.item(0)) // Nothing shows up - undefined
console.log(viewports[0].childNodes.item(1)) // Nothing shows up - undefined
console.log(viewports[0].children.item(0)) // Nothing shows up - undefined
console.log(viewports[0].children.item(1)) // Nothing shows up - undefined
console.log(viewports[0].childNodes[0]) // Nothing shows up - undefined
console.log(viewports[0].childNodes[1]) // Nothing shows up - undefined
console.log(viewports[0].children[0]) // Nothing shows up - undefined
console.log(viewports[0].children[1]) // Nothing shows up - undefined
console.log("Here")
var second_canvas = viewports[0].children.item(1).cloneNode(true); // Error that is detailed below
viewports[1].appendChild(second_canvas);
Error that cloning the node gives: Cannot read property 'cloneNode' of undefined
.