I would like to use DocumentFragment and querySelector to make and modify DocumentFragments. I am using some code from Inserting arbitrary HTML into a DocumentFragment to create the fragments from HTML strings:
stringToDocumentFragment = function(html_string) {
var frag = document.createDocumentFragment();
var holder = document.createElement("div")
holder.innerHTML = html_string
frag.appendChild(holder)
return frag
}
And it works:
test_one = stringToDocumentFragment('<one><two>test</two></one>')
#document-fragment
test_one.querySelector('one')
> <one>...</one>
However, if I use elements like <html>
or <body>
, it fails:
test_two = stringToDocumentFragment('<html><body>test</body></html>')
#document-fragment
test_two.querySelector('html')
null
The behaviour is identical in both Chrome and Firefox.