Re: Using $$ within an element.

Mark Holton
Sun, 03 Jun 2007 19:46:25 -0000

Chris,
Many thanks!  I did not know about ''first-child'' or
''>'' ... have been using
$$(''a''), $$(''#foo''), etc for grabbing arrays
of links, divs, etc.  ...this
takes it a step further!  ...the power of Prototype is awesome.
cheers,
Mark

On 6/3/07, Christophe Porteneuve
<tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>
wrote:
>
>
> Mark Holton a écrit :
> > Wild.  ...can I trouble you for a short explanation on that, Chris?
>
> Sure thing.
>
> > $$(''#box > *:first-child a.tooltip'')
>
> A bona-fide CSS3 selector:
>
>         #box -> filters on a container with id="box"
>         >    -> following selector must pertain on child, not
descendant
>         *    -> we don''t care about the tag name
>         :first-child -> CSS3 pseudo-class that restricts the previous
>                         selection to first children only, hence the
>                         equivalence with .firstDescendant()
>         (space)      -> now we can go to any depth
>         a.tooltip    -> a-tag elements with a "tooltip" CSS
class
>
> > Selector.findElements($(''box'').firstDescendant(),
'' a.tooltip'')
>
> $$(...) is basically Selector.findElements(document, ...).
>
> This method performs the selection within the scope of the DOM node it
> takes as its first argument.  So using it explicitly lets you specify
> the scope.
>
> ''HTH
>
> --
> Christophe Porteneuve a.k.a. TDD
> "[They] did not know it was impossible, so they did it." --Mark
Twain
> Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
>
> >
>