[whatwg] getElementsByAttr

Sander html5 at zoid.nl
Sat Jul 7 18:22:04 PDT 2007

Dan Dorman schreef:
> In fact, it
> could be useful to enforce retrieval of a single element, for
> performance reasons if nothing else.
That seems to be the case.

> I concede a conceit, though:  I think accessing selectElements()[0]
> every time I want a single time is ugly.
But what if you only want the last element or the 5th? I guess selecting 
the last element can be just as usefull as the furst.

> I'm curious, Sander:  what is the objection to having both?

It seemed a bit overdone and somewhat arbitrary (why not an option for 
selecting the last element?). I think performance is a good argument why 
it may not be overdone, but only providing a single selecting option for 
the first element and not for the last one still seems arbitrary. I 
don't think there's a performance argument behind that decision, but I 
can very well be wrong.
Anyway, if there is going to be a method for selecting a single element 
I'd rather like to see both (first and last):


These method names (the single selecting method names being variations 
on that of the plural method instead of the other way around) would be 
more clear as well in my opinion.


More information about the whatwg mailing list