W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: innerHTML in DocumentFragment

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Fri, 4 Nov 2011 11:19:33 -0700
Message-ID: <CAAWBYDD5H_oNvtPVH2Qmkm1YAZg-XRiVHddjuN8mr1vSqdUEdQ@mail.gmail.com>
To: Daniel Cheng <dcheng@chromium.org>
Cc: João Eiras <joaoe@opera.com>, public-webapps WG <public-webapps@w3.org>
2011/11/4 Daniel Cheng <dcheng@chromium.org>:
> In that example, there was a clear context element though--I'd argue
> that Range.createContextualFragment should have been used instead.
>
> It seems like the general use of such a function would be to add some
> nodes from a snippet of HTML markup into a div for example, where
> synthesizing the correct context elements would make more sense.

Sorry, I referred only to Yehuda's first example for simplicity.
Please read the rest of Yehuda's first post, as his later examples
both (a) break (or at least become unnecessarily difficult) if
contextual wrappers are automatically added, and (b) don't have a
context element to apply at the time the DOM is being constructed.

If one is adding nodes into a div, one would *not* write:

var frag = parse("<tr><td>foo</tr>")
div.appendFragment(frag);

...because that would be nonsensical.  In particular, jQuery does
*not* do anything special when they see this sort of pattern - they go
to some effort to ensure that the fragment contains only the <tr> and
descendants, and then would directly insert it into the DOM as a child
of the <div>.

~TJ
Received on Friday, 4 November 2011 18:20:40 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:48 GMT