Is it possible to have DocumentFragments contain tr, th or td tags?
If I do this:
var template = document.createRange().createContextualFragment(
'<table></table>'
);
console.log(template.childNodes);
I get the output of [table]
.
If I do this:
var template = document.createRange().createContextualFragment(
'<td></td>'
);
console.log(template.childNodes);
I get the output of []
!!!?!?
If I do this:
var template = document.createRange().createContextualFragment(
'<td><p></p></td>'
);
console.log(template.childNodes);
I get [p]
??!?!?!??!?!??!
And finally if I do this:
var template = document.createRange().createContextualFragment(
'<span><td></td></span>'
);
console.log(template.childNodes);
I get [span]
- where's the td gone??!
I don't understand the inconsistency here. Is it possible for document fragments to only hold certain elements? What I would like to do is do something akin to the second this above, and then retrieve the td using querySelector
.
Thanks
document.createRange()…
and not justdocument.createDocumentFragment()
? The later can contain just<td>
s perfectly well. – Occupation