[whatwg] getElementsByClassName()
Ian Hickson
ian at hixie.ch
Mon Oct 23 13:03:03 PDT 2006
On Sun, 22 Oct 2006, Anne van Kesteren wrote:
>
> On Sat, 21 Oct 2006 09:36:37 +0200, Ian Hickson <ian at hixie.ch> wrote:
> > This omnibus edition of your WHATWG mail includes replies to 50 or so
> > separate e-mails about getElementsByClassName(). Thanks to everyone for
> > their comment on this issue.
>
> So what's the use case over matchAll(".foo.bar.baz") ..?
None; it's just a complementary method in line with getElementById(),
getElementsByTagName(), and getElementsByName() methods. (Also, it returns
a live list, instead of a static list.)
On Mon, 23 Oct 2006, James Graham wrote:
>
> I guess the question is "why bother with getElementByClassName if a full
> getElementByCSSSelector-type method is available"?. Possible answers
> would include speed and ease of use but I'm not sure either applies
> here.
I think there's room for both. I don't have a strong opinion, though; if
other people think we should not add getElementsByClassName() then please
speak up.
On Mon, 23 Oct 2006, Dean Edwards wrote:
>
> This has been debated to death. People want this function. So I think we
> should add it. The only arguments against are that there are potentially
> better solutions, like matchAll/matchSingle. I don't think that is a
> good enough reason to not include it. First, it is analogous to
> getElementsByTagName. Second, alternatives are not currently
> implemented.
>
> It is not uncommon for API's to provide more than one way to achieve the
> same end. I don't see why the DOM should be any different. It is not
> going to break anything and people want it -- so let's spec it. I
> haven't heard a good argument against inclusion yet and we are on the
> 87th comment in this thread.
I agree with Dean.
On Mon, 23 Oct 2006, Jonathan Worent wrote:
>
> There seems to be a question on how confusing a method would be for
> developers. I went and asked 4 people I know that are just learning
> Javascript for the first time. For two of them javascript is their first
> programing language, the other two already know other languages.
>
> Given this markup:
> <p class="foo bar">Para 1</p>
> <p class="bar foo">Para 2</p>
> <p class="foo baz">Para 3</p>
>
> All expected that getElementsByClassName("foo bar"); would match "foo
> bar" exactly in the class name and only return Para 1.
>
> When asked if they would prefer a comma separated list or an array,
> there were mixed feelings. Three indicated a preference to a comma
> separated list, the other said he would expect to pass an array. Given
> this I would suggest not using a space delimited list.
Ok, that's a compelling argument. I've removed the string version. We're
down to just the array form now. If people want to call the method with a
single class, they have to use square brackets; if they want to call it
with a space-separated list of classes, they have to use .split() or some
such.
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list