[whatwg] getElementsByClassName()

Gervase Markham gerv at mozilla.org
Fri Feb 3 05:39:26 PST 2006

ROBO Design wrote:
> I believe there's some disagreement on what is this function supposed to
> do.

Well, not according to the current spec, which says:

> 1. Should it return *all* elements which have *all* the class names wanted?

this one. Of course, you may disagree with the spec.

> 4. Should the order matter?

No, because class name ordering does not matter in the source or in CSS.

> I also believe this function will always be confusing, no matter what.
> To drop all confusion just rename it to getElementsByCSSselector() and
> you get the exact idea to as what you are supposed to provide as an
> argument (if you know CSS). Yet, this is something Ian Hickson said is
> beyond the purpose of WHATWG.

That turns the function into something which is dependent on CSS rather
than just dependent on the markup language. That is a reasonably large
change in scope IMO.

CSS selector parsers in JS have been written (I believe Dean Edwards has
one); but such things would be much easier to implement if you had
getElementsByClassNames() to go with getElementsById().


More information about the whatwg mailing list