W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2004

[whatwg] [WA1] getElementsByClass

From: Mark Schenk <css@markschenk.com>
Date: Thu, 26 Aug 2004 16:17:13 +0200
Message-ID: <opsdcfaz0b31wfpa@imladris.kvz.local>
I'm very happy to see the getElementsByClass() method introduced in WA1,
that is definitely something missing from current DOM specs. However,
there seems to be no way defined for selecting elements with multiple
class names.

Let's say we have the following elements:

<div class="green" />
<div class="green car" />
<div class="car green" />
<div class="car green british" />

If I use getElementsByClass('green') I would select all four of the
elements. If I use getElementsByClass('car') then I would select the last
three.

What happens if I want to select all elements with class="car green" (and
that selection should include the equivalent class="green car")? That is
currently undefined. And let's assume that this was implemented and if I
were to search for getElementsByClass("car green") would it also select
the fourth one? Or should it only select completely matching classes?

So in other words, in what way would getElementsByClass() be equivalent to
the CSS3 Selectors[1]? Would it be equivalent to:

E[class~="bar"]
(and in the case of multiple classes we switch to E.bar.foo which is
equivalent to E.foo.bar)

or to:
E[class="bar"]

I think that in practice the first option would be the most useful.

-- 
Mark Schenk
Received on Thursday, 26 August 2004 07:17:13 UTC

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