W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2011

[whatwg] documentFragment and innerHTML

From: <raf@ratherodd.com>
Date: Fri, 25 Feb 2011 12:56:38 -0800
Message-ID: <82a34f51c46a77bae29ac2171dad8314.squirrel@webmail.ratherodd.com>

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.

Received on Friday, 25 February 2011 12:56:38 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:31 UTC