What does $$ mean in Javascript?

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));
}

Answers:

Answer

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-$$

Answer

$ 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.

Answer

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.

Answer

$ 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.

Answer

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/ (now owned by a domain grabber)

"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."

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.