Re: childElements, childElementCount, and children

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 UTC