W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2009

Re: childElements, childElementCount, and children

From: Jonas Sicking <jonas@sicking.cc>
Date: Tue, 20 Oct 2009 15:27:24 -0700
Message-ID: <63df84f0910201527u435d9561t9e6d03461a0e5b1@mail.gmail.com>
To: Doug Schepers <schepers@w3.org>
Cc: "www-dom@w3.org list" <www-dom@w3.org>
On Tue, Oct 20, 2009 at 2:07 PM, Doug Schepers <schepers@w3.org> wrote:
>> In this particular case, I think anything that's implemented in all of
>> the major browser engines should be an official standard, not just de
>> facto.
>
> Agreed, which is why I've started off DOM4 Core as I did.
>
> I don't feel too strongly about having both .children and .childElements,
> but I do think that .children is a little problematic for authors... they
> will always have to check to see if Comment nodes are included, because of
> the large marketshare for older versions of IE, while .childElements allows
> them to write simple, clean, efficient code, which is the whole point of an
> element-based API.

Comment nodes are fairly rarely used. A webpage that doesn't want to
worry about if comment nodes are going to be included in .children or
not can simply avoid using comment nodes in those parts of the DOM.
And an implementation that simply wants to iterate over all child
elements can simply check for comment nodes and skip them as
appropriate. And in the case where you're only looking for a certain
set of element names, you don't even need to make extra effort to skip
comments.

Has any vendor actually expressed a preference in implementing a new
.childElements property over simply using .children? Has web
developers? It seems like Garrett did express a preference in not
reusing .children, but that is the only person I've heard that
feedback from. All other feedback I've received has been to ask us to
implement .children as a list of child elements.

> I also prefer ElementCollection over HTMLCollection, especially for
> environments where more XML is used.  I don't know if there are any deeper
> issues that would advantage one over the other, but I think it would be
> confusing to authors to collect non-HTML elements in something labeled
> HTMLCollection.

I think a simple NodeList should suffice. It's mostly by accident that
Gecko uses HTMLCollection for .children and .getElementsByTagName().
I'd be prepared to change that to simply using a NodeList and see if
that breaks any content, I expect it not to.

/ Jonas
Received on Tuesday, 20 October 2009 22:28:19 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:04 GMT