[whatwg] getElementsByClassName()

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()
and getElementsByClassNameNS()

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,


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