views:

1740

answers:

7

I am looking at some javascript code and it has this in a function:

$$('.CssClass').each(function(x) { .... } )

I get that the intent is to apply the anonymous function to each element with a class of CssClass, but I can't work what the $$ refers to ... and can't google for $$!

Update: thanks for the hints. The javascript comes from the iPhone look-alike library: jPint which includes the prototypejs library, and does define $$ as:

function $$() {
  return Selector.findChildElements(document, $A(arguments));
}
+4  A: 

Are you looking at a library such as mootools by chance? This is used as a short-hand to certain types of objects by accessing the DOM. They do things like $('myElement') to access page elements for example.

Kezzer
+1 cause you hit the nail on the head this is likely from a framework. And I like your gravatar.
Unkwntech
I believe Prototype has a $$ function as well.
ceejayoz
I use mootools at work for writing Intranet systems, shorthand techniques like this are handy. I was equally confused by them when I saw them, thinking that they were an operator of some kind.
Kezzer
+1  A: 

$ is a valid function name in javascript. So something defines a function $$ that takes a string looking for some class called .CssClass and returns a object where you call each on.

I know that jQuery defines a function called $ at least that does similar things.

Johannes Schaub - litb
A: 

This looks like jQuery code which uses $('…') to match elements. I think that the code uses multiple frameworks and more than one of them uses $ as a short form of it's class.

They provide functions to rename $ to other names, in this case I think it's the same as jQuery(…)

See here for more information: http://docs.jquery.com/Core/jQuery.noConflict

Georg
+10  A: 

Probably this prototype function:

$$(cssRule...) -> [HTMLElement...]

Takes an arbitrary number of CSS selectors (strings) and returns a document-order array of extended DOM elements that match any of them.

http://www.prototypejs.org/api/utility#method-$$

Tom Haigh
Mm. Sorry for the edit, I was trying to add brackets to the link so it'd work, but I guess you had tried that already. Oh well. :(
Paolo Bergantino
+1  A: 

Any chance you are looking at a MooTools script? http://www.consideropen.com/blog/2008/08/30-days-of-mootools-12-tutorials-day-2-selectors/

"The $$ lets you quickly select multiple elements and places them into an array (a type of list that lets you manipulate, retrieve, and reorder the list in all sorts of ways). You can select elements by name (such as div, a, img) or an ID, and you can even mix and match."

Maxfrank
A: 

Most likely a shorthand function name that handles the DOM accessing of the specified arguments, whether tag name or object id.

As per above, you're likely in MooTools or jQuery.

jerebear
How did I get voted down? That's the same answer as the one that was chosen. $$ is the function name!
jerebear
+1  A: 

$ is an ordinary symbol character, thus "$", "$$", "$$$" are ordinary variables.

the meaning of $ depends upon the libraries that are in use; in jQuery the $-function creates a jquery object from a css selector, e.g. $("DIV") is a collection of all DIVs in the current document.

mfx