admin管理员组文章数量:1322350
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?
本文标签: javascriptHow to loop through DocumentFragment39s childrenStack Overflow
版权声明:本文标题:javascript - How to loop through DocumentFragment's children? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742113614a2421367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论