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

[whatwg] getElementsByClassName()

From: Shadow2531 <shadow2531@gmail.com>
Date: Fri, 3 Feb 2006 08:24:19 -0500
Message-ID: <6b9c91b20602030524n2991b585iaa8b2546fbb8144a@mail.gmail.com>
On 2/3/06, Gervase Markham <gerv at mozilla.org> wrote:
> This seems like a sensible change. Call it getElementsByClassNames()
> would make it obvious that if you supply multiple class names, you get
> only elements with all those names. And it would be a reasonably obvious
> reduction that if you just supply a single name, you would get all
> elements which had that one class name.
>
> So we've ended up with:
>
> elem.getElementsByClassNames("foo");
> and
>
> elem.getElementsByClassNames(["foo", "bar"]);
> or
> elem.getElementsByClassNames("foo", "bar");
> or both.

O.K.

> Are there similar functions in the DOM at the moment which can take
> multiple arguments? Do you pass an array or multiple individual
> arguments, or can you do both?

For getElementsByClassNames( var )
var could be an object or a string.  The function could use typeof to
check which one it is. If it's an object, the function could check its
elements to make sure they are strings. So, you could pass a list or a
string.

For getElementsByClassNames("string1", "string2", "string3",
"stringN"), the function has an 'arguments' array that will output
"string1,string2,string3,stringN".

So, it should be possible to support, passing 1 or more strings, or 1
or more arrays, or a mixture. We don't want to go crazy though.

I'd prefer to just be able to pass one or more strings and keep it at
that. However, if you had an array of strings, you'd then be forced to
build a call to getElementsByClassNames() via eval() or use some other
method.

Do we need to be able to pass an array of arbitrary classnames?

burnout426
Received on Friday, 3 February 2006 05:24:19 UTC

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