W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2006

[whatwg] getElementsByClassName()

From: Shadow2531 <shadow2531@gmail.com>
Date: Fri, 3 Feb 2006 05:31:02 -0500
Message-ID: <6b9c91b20602030231j5a03fb32q354c0faef36d4108@mail.gmail.com>
On 2/3/06, Gervase Markham <gerv at mozilla.org> wrote:
> Musing...
>
> If you have:
>
> <p class="foo bar">Fred</p>
> <p class="bar foo">Barney</p>
> <p class="foo baz bar">Wilma</p>
>
> which should be picked up by getElementsByClassName("foo bar")?
>
> In the "string split" mode, it would pick up all three. However, I
> suggest that designers might be misled by this interface into thinking
> that it only picks up the first one - which matches exactly.
>
> So I think a multiple-argument interface would remove this possible
> confusion, and make things more obvious than a whitespace-splitting
> interface.
>
> getElementsByClassName("foo", "bar") ideally, but if that's hard, then
> getElementsByClassName(["foo", "bar"]);
>
> So I agree with Brad, I think :-)
>
> Gerv
>

In <http://my.opera.com/community/forums/topic.dml?id=121081> I wrote
2 prototypes for Opera and Firefox: getElementsByClassName()
<http://my.opera.com/burnout426/homes/files/getElementsByClassName.zip>
and getElementsByClassNameNS()
<http://my.opera.com/burnout426/homes/files/getElementsByClassNameNS.zip>.

I just threw them together as a proof of concept, but I have no doubt
that the class attribute value should be a space separated list of
classnames and the getElementByClassName function should split up the
class attribute value into an array and then search for the class name
to see if there's a match (Or use regex to be simpler). I also added a
case insensitve search option.

As the case above, getElementByClassName("foo bar") doesn't make sense
to me because there are 2 class names in there and it's
getElementByClassName, not getElementsByClassName*s*().

In getElementByClassName("foo bar") , "foo bar" should be normalized
"foo" and therefore match all 3 because they all have "foo" in the
class attribute value.

getElementsByClassName*s*() should be a separate function and I agree,
getElementsByClassNames*s*("foo", "bar") would be great if possible.

Just my thoughts,

burnout426
Received on Friday, 3 February 2006 02:31:02 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:26 UTC