document.getElementsByTagName
returned me a NodeList object.
I would like to remove some items (let\'s say I would like to remove the first item from th
var MySet = { 0: {value: document.body, enumerable: true}, 1: {value: document.head, enumerable: true}, 2:{value: document.documentElement, enumerable: true}, length: {value: 3}};
var protoNodelist = document.createDocumentFragment().childNodes;
var MyNodelist = Object.create(protoNodelist, MySet);
MyNodelist; // Output: NodeList {0: body, 1: head, 2: html, length: 3}
removeNode(MyNodelist, 1); // Output: NodeList {0: body, 1: html, length: 2}
function removeNode(NodeList, i){
var newElementSet = {};
var newElementSeti = 0;
for(NodeListi = 0; NodeListi < NodeList.length; NodeListi++){
if(NodeListi != i){
newElementSet[newElementSeti] = {value: NodeList[NodeListi], enumerable: true};
newElementSeti += 1;
};
};
newElementSet['length'] = {value: newElementSeti};
var nodelist = document.createDocumentFragment().childNodes;
var newNodelist = Object.create(nodelist, newElementSet);
newNodelist.__proto__ = newNodelist.__proto__.__proto__;
return newNodelist;
};