On Thu, Jun 7, 2012 at 2:45 AM, Henri Sivonen <hsivo...@iki.fi> wrote:
> On Wed, Jun 6, 2012 at 7:13 PM, Tab Atkins Jr. <jackalm...@gmail.com> > wrote: > > A call like "document.querySelectorAll('p')" doesn't *want* to get the > > <p> inside the template. > > I think it's backwards to assume that querySelectorAll() works a > particular way and that's that's not what authors want and to change > the DOM in response. > > You could make this argument about any assumption anyone makes anywhere which in any way adds features. <template> is a pretty fundamentally different use of the DOM from existing practices and it seems like violations of existing rules are likely. That said, is a best practice here to put <template> in the <head> if web developers are inclined to inline the template declaration? At least then you can rely on document.body.querySelectorAll(). That seems like the cleanest approach from a developer's perspective and is consistent with practices like putting embedded CSS in the <head>. Alec > There are various solutions that don't involve drastic changes to the > correspondence between the markup and the DOM, for example: > > * Invoking querySelectorAll() on a wrapper element that's known not to > be a parent of the templates on the page. > > * Using a selector that fails to match elements whose ancestor chain > contains a template element. > > * Introducing an API querySelectorNonTemplate(). (Don't say "All" if > you don't mean *all*). > > Even though XML has fallen out of favor, I think violations of the DOM > Consistency principle and features that don't work with the XHTML > serialization should be considered huge red flags indicating faulty > design. > > -- > Henri Sivonen > hsivo...@iki.fi > http://hsivonen.iki.fi/ > >