1

i have created a NodeList with nodeList = document.createDocumentFragment().childNodes;,

then i have set nodeList[0] = document.getElementById("foo");

everything works fine, the only problem is, that nodeList.length stays 0

i have allready tried to change an Array to a NodeList. Also i have tried to use a fragment, appended children and changed them afterwards and returned the childnodes.

i cannot just append the original children, because they get removed somewere else then.

what am i missing?

yes i know i could just use an Array, but i want to NodeList element

Friedrich
  • 2,211
  • 20
  • 42

1 Answers1

1

I am not sure how duplicate works so i will add answer here

from documentation https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment?redirectlocale=en-US&redirectslug=DOM%2FDocumentFragment DocumentFragment has child property as read only so you cant write to it, instead use appendChild();

var nodeList = document.createDocumentFragment();
nodeList.appendChild(document.getElementById("foo"))
Vova Bilyachat
  • 18,765
  • 4
  • 55
  • 80