我有一个 HTMLCollection 对象,可以用它来操作 HTMLCollection 的内容。我想知道如何向 HTMLCollection 的第一个、最后一个或任何指定索引添加一个 div 元素。请给出建议。这里 nDivs 是 HTML Collection。
var Div = document.createElement('div');
for(i=0; i<9; i++){
Div.appendChild(nDivs[0].children[0]);
}
Div.id = nDivs[0].id;
nDivs[0].parentNode.removeChild(nDivs[0]);
nDivs.appendChild(Div); //this is creating problem..need an alternative to this
document.getElementById("ABC").appendChild(nDivs[nDivs.length - 1]);