W3C home > Mailing lists > Public > public-webapi@w3.org > January 2007

Re: [selectors api] Why two methods?

From: Anne van Kesteren <annevk@opera.com>
Date: Thu, 25 Jan 2007 14:53:15 -0500
To: David Håsäther <hasather@gmail.com>
Cc: public-webapi@w3.org
Message-ID: <op.tmp6u1od64w2qv@id-c0020>

On Thu, 25 Jan 2007 14:48:35 -0500, David Håsäther <hasather@gmail.com>  
>>> Why does the Selectors API define two methods for retrieving nodes?
>>> I understand that there are speed gains by having a method that grabs
>>> just the first node, but how often do you want to do that? Don't you
>>> want to grab the second node as often? Or the last?
>>  How do you mean?
> Sorry for not being clear.
> What I mean is, why does grabbing the first node deserve its own method?  
> Is that really a common thing to do, grabbing the first node? More  
> common than grabbing the second or last node for instance?

Do you have a concrete example? Say that in the following document we want  
to get one of the <p> elements:


We'd do this as follows:

  1. document.getElementBySelector("html > p")
  2. document.getElementBySelector("html > p:not(:first-child)")
  3. document.getElementBySelector("html > p:last-child")

(Or using an equivalent group of selectors.)

Anne van Kesteren
Received on Thursday, 25 January 2007 19:53:29 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:16:22 UTC