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

[whatwg] createContextualFragment in detached contexts

From: Ryosuke Niwa <ryosuke.niwa@gmail.com>
Date: Thu, 29 Sep 2011 16:10:29 -0700
Message-ID: <CABNRm60qjG5tP9W9xp1_8U=kC-93VaZTAdkrS3jJ2mnncdfGzQ@mail.gmail.com>
Can't authors use createElement? Or are you specifically concerne the case
where authors want to use createContextualFragment?

- Ryosuke
On Sep 29, 2011 3:37 PM, "Erik Arvidsson" <arv at chromium.org> wrote:
> Currently there is no easy way to create a tbody (and others from
> markup). To do this correctly people have to go through ugly hacks
> like what jQuery does [1] where they wrap the HTML string with the
> right context elements and then grab the nodes inside that.
>
> I would like to propose a change to createContextualFragment [2].
>
> If the context object is in a detached state, then relax the parsing
> rules so that all elements are allowed at that level. The hand wavy
> explanation is that for every tag at the top level create a new
> element in the same way that ownerDocument.createElement would do it.
> This would allow the following to work.
>
> var df =
document.createRange().createContextualFragment('<tbody><tr><td>Hi</tbody>
> text <option></option>');
> assertEquals(3, df.childNodes.length);
> assertEquals('TBODY', df.childNodes[0].tagName);
> assertEquals(' text ', df.childNodes[1].textContent);
> assertEquals('OPTION', df.childNodes[2].tagName);
>
>
>
> [1] https://github.com/jquery/jquery/blob/master/src/manipulation.js#L643
> https://github.com/jquery/jquery/blob/master/src/manipulation.js#L32
> [2]
http://html5.org/specs/dom-parsing.html#dom-range-createcontextualfragment
>
> erik
Received on Thursday, 29 September 2011 16:10:29 UTC

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