Click to See Complete Forum and Search --> : what the $*% is $() ?


doug8888
August 1st, 2007, 07:17 PM
I've started working with ajax, and keep getting confused about what appears to be a javascript thing.

What is '$' ?

I've seen references like, "the $() function" and code like, "var $ = blahblah".

So what's this about? Is it an actual Javascript syntax, operator or function? Or is it a standard ajax convention?

And... what can it do? (since it's hard to google on '$()').

PeejAvery
August 2nd, 2007, 08:38 AM
That is just JavaScript. $ can be used as a variable or a function. It is no different from...

var x = 10;
var $ = 10;

function x(){
alert('This is a function!');
}
function $(){
alert('This is also a function!');
}

PeejAvery
August 2nd, 2007, 08:39 AM
[ moved ]

andreasblixt
August 2nd, 2007, 12:06 PM
In JavaScript function libraries (for example: www.prototypejs.org), $ is commonly used as a function that retrieves an element by ID (and is sometimes even extended to support CSS- or XPath-esque selectors).

doug8888
August 2nd, 2007, 05:59 PM
In JavaScript function libraries (for example: www.prototypejs.org), $ is commonly used as a function that retrieves an element by ID (and is sometimes even extended to support CSS- or XPath-esque selectors).

Ah... ok. Is the use consistent across ajax libraries? (give or take some functionality)

PeejAvery
August 2nd, 2007, 11:07 PM
That can all depend on the person who wrote the library. For the most part, I find them not too largely common.