W3C home > Mailing lists > Public > whatwg@whatwg.org > July 2007

[whatwg] getElementsByAttr

From: Sander <html5@zoid.nl>
Date: Fri, 06 Jul 2007 23:38:37 +0200
Message-ID: <468EB65D.4000908@zoid.nl>

Dan Dorman schreef:
> On 7/6/07, Sander <html5 at zoid.nl> wrote:
>> I haven't read the whole draft yet so maybe it's in there, but can you,
>> or anyone else, explain why there is both a selectElement and a
>> selectAllElements method?
> I'm no authority, but:
> If you know you're after one element, you get to deal with it directly
> rather than first referencing the only contents of a single-element
> array.
But document.selectAllElements("#first")[0] would do the trick.

> That's not a big deal, I suppose, but a some benefits are
> reduced and more readable code (i.e., reading through the code would
> make it obvious that only a single element was desired in any given
> case).
True, but you can also make this obvious by choosing descriptive names 
for your variables.

> Also, it sort of provides a correlation with getElementById,
> and while I find the symmetry somewhat appealing, I'm not sure if that
> motivated anybody's thinking.
But there neither are singular versions of getElementsByTagName and 

If this is really the only reason and referencing the 0 index is not an 
option for the specs (maybe because in other languages than JavaScript 
calling the first item from an empty list gives an error? I just don't 
know) then I'd prefer an optional extra argument.

Received on Friday, 6 July 2007 14:38:37 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:57 UTC