In the prototype.js library, what doe the $$ function do, and how do you use it --Will Merrell
Hey Will,
$$ function is used for finding DOM elements by simple CSS selector strings.
Example: Find all <img> elements inside <p> elements with class
"summary", all inside
the <div> with id "page". Hide each matched <img> tag.
$$(''div#page p.summary img'').each(Element.hide)
Hope this helps!
Thanks,
Mandy.
-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]On
Behalf Of Will
Merrell
Sent: Wednesday, June 07, 2006 7:55 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] What if $$() for?
In the prototype.js library, what doe the $$ function do, and how do you
use it
--Will Merrell
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
$$() is like $() but selects an array of elements via a CSS selector.
Thus,
$$(''div.someclass'')
returns an array of all DIV elements on the page that have a CSS class
of "someclass" set.
For example, you can do:
$$(''#info p.notice'').each(Element.hide);
This will hide all P elements that have a CSS class of "notice" that
are inside
the element with id "info".
-Thomas
Am 07.06.2006 um 04:25 schrieb Will Merrell:
> In the prototype.js library, what doe the $$ function do, and how
> do you use it
>
> --Will Merrell
>
>
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
--
Thomas Fuchs
wollzelle
http://www.wollzelle.com
http://www.fluxiom.com :: online digital asset management
http://script.aculo.us :: Web 2.0 JavaScript
http://mir.aculo.us :: Where no web developer has gone before
out of interest, is there an equivilent get-elements-by-classname in 1.4
? I couldn''t see one and I am curious about what strategy people use in
1.4..
Best
Matt
Maninder, Singh wrote:
> Hey Will,
>
> $$ function is used for finding DOM elements by simple CSS selector
> strings.
>
> Example: Find all <img> elements inside <p> elements with
class
> "summary", all inside
> the <div> with id "page". Hide each matched <img>
tag.
>
> $$(''div#page p.summary img'').each(Element.hide)
>
> Hope this helps!
>
> Thanks,
> Mandy.
>
>
>
> -----Original Message-----
> From:
rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]On
Behalf Of Will
> Merrell
> Sent: Wednesday, June 07, 2006 7:55 AM
> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> Subject: [Rails-spinoffs] What if $$() for?
>
>
> In the prototype.js library, what doe the $$ function do, and how do you
> use it
>
> --Will Merrell
>
>
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
> $$(''#info p.notice'').each(Element.hide); > > This will hide all P elements that have a CSS class of "notice" that > are inside > the element with id "info".I''ve had problems getting such a thing to work with the $A function (it''s my understanding that internally $$ creates an Array object similar to $A). $A([array of elements]).each(Element.hide); IE 6 throws an error. Is something that was recently fixed? I can''t remember if I tried it with the latest release or a previous one, so I was just curious if it''s safe to try again. Greg
Am Mittwoch, 7. Juni 2006 11:54 schrieb Maninder, Singh: [...]> Example: Find all <img> elements inside <p> elements with class > "summary", all inside the <div> with id "page". Hide each matched <img> > tag. > > $$(''div#page p.summary img'').each(Element.hide)Out of curiosity, how does the Element method know about the iterator? Somehow i had expected that Element.hide() takes a param. Best Regards, Dirk Eschler -- Dirk Eschler <mailto:dirk.eschler-hi6Y0CQ0nG0@public.gmane.org> http://www.krusader.org
Dirk Eschler wrote:> Am Mittwoch, 7. Juni 2006 11:54 schrieb Maninder, Singh: > [...] >> Example: Find all <img> elements inside <p> elements with class >> "summary", all inside the <div> with id "page". Hide each matched <img> >> tag. >> >> $$(''div#page p.summary img'').each(Element.hide) > > Out of curiosity, how does the Element method know about the iterator? Somehow > i had expected that Element.hide() takes a param.Element.hide is different from Element.hide(). The first is a subroutine (each() takes a subroutine as a param and then passes the current iteration to it), the second executes the subroutine. -- Michael Peters Developer Plus Three, LP