[whatwg] documentFragment and innerHTML

raf at ratherodd.com raf at ratherodd.com
Fri Feb 25 12:56:38 PST 2011


Hello,


I originally first posted this on Mozilla's bugzilla and was asked to
discuss this issue here.

It is not a major issue, but as someone who uses documentFragments, this
has irked me on a few occasions.

Suppose you want to insert some HTML into a node, specifically after a
node that isn't the last node. This is easy enough with DOM methods
(insertBefore) but if you have a lot of stuff to insert, innerHTML is less
verbose than lots of createElements and appendChilds. To do this with
innerHTML though, one would have to do some messy string manipulation of
the existing node's innerHTML, and then update it.

Enter documentFragment. It would be very useful in this scenario to just
create a documentFragment, chuck the new HTML into it via innerHTML and
then use insertBefore to put the fragment into the right place in the node
we want to augment.

I realise this is a niche scenario that is not often encountered, but I'd
be interested in the rationale behind not implementing it, or whether
others think it would be a good idea to add this feature. Boris Zbarsky
indicated something about contexts to parse in that I didn't understand,
so hopefully someone can enlighten me.

Rafael



More information about the whatwg mailing list