How can I loop through DocumentFragment
childNodes
? I've tried doing the following:
console.log(result.childNodes);
console.log(result.childNodes.length);
But length seems to be 0 even if I can see the actual child nodes in firebug, like:
[div#tiptip_arrow]
0
Update:
/
This is not exactly what I'm doing, but demonstrates the problem: when I have a look in Firebug console, I see that the fragment has child nodes, but console.log(result.childNodes);
yields []
for some reason. Why is that?
How can I loop through DocumentFragment
childNodes
? I've tried doing the following:
console.log(result.childNodes);
console.log(result.childNodes.length);
But length seems to be 0 even if I can see the actual child nodes in firebug, like:
[div#tiptip_arrow]
0
Update:
http://jsfiddle/ve5hf/
This is not exactly what I'm doing, but demonstrates the problem: when I have a look in Firebug console, I see that the fragment has child nodes, but console.log(result.childNodes);
yields []
for some reason. Why is that?
-
1
of course it has no child Nodes it's an empty document fragment. Note that the reason you see data in
childNodes
when you logresult
is becauseconsole.log
is live. – Raynos Commented Jan 3, 2012 at 17:33
1 Answer
Reset to default 8var o = document.createDocumentFragment();
o.appendChild(document.createElement('div'));
var childNodes = o.childNodes;
for (var i = 0, len = childNodes.length; i < len; i++) {
console.log(childNodes[i].tagName);
}
.length
does work.
We need more specifics. How do you create the document fragment? What browser?