As of right now DocumentFragments don’t have the innerHTML property.

How come?

This should be possible:

var frag = document.createDocumentFragment();
frag.innerHTML = "<div><h1>Hello World</h1></div>";



There have been several discussions in the past, but not much progress. The biggest issue is that the markup given to the value needs context where it resides.

[1] [2]


More importantly than being able to set innerHTML on DocumentFragment, to me, would be an ability to create a fragment pre-filled with a provided array of child elements, like cre.

What about evaluating it (when set) as if it were in the root context of a fresh document (with the elements being appended)? For reasonably well-formed HTML (ie. not omitting contextual end tags), what problems would arise? Are there elements that cannot be parsed within the root context?