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

[whatwg] documentFragment and innerHTML

From: Aryeh Gregor <Simetrical+w3c@gmail.com>
Date: Fri, 25 Feb 2011 16:56:06 -0500
Message-ID: <AANLkTikioCxru1JMkDm-cbQ8DSX9oW=_qzFN08xpcx3G@mail.gmail.com>
On Fri, Feb 25, 2011 at 3:56 PM,  <raf at ratherodd.com> wrote:
> 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.

Isn't this exactly what insertAdjacentHTML() does?

On Fri, Feb 25, 2011 at 4:18 PM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
> If you want to parse this string:
> ?<form><tr><td>Some text</td></tr></form>
> then the DOM it produces depends on whether it's being parsed in the context
> of a <table> parent element or not. ?Try setting the innerHTML of a <table>
> and a <div> to the above string, and examine the resulting DOM trees.
> That's what I meant when I said that to properly parse a string you need to
> know the context it's being parsed in.

Well, you could create the DocumentFragment using
createContextualFragment() if you liked.  But insertAdjacentHTML() is
a better fit.
Received on Friday, 25 February 2011 13:56:06 UTC

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