I have some new code that i am responsible for, and do not know what the $ does in javascript. Can someone enlighten me in this ?
For example, see the code below:
Code:
function shiptostateChange(shipgroup, isUpgradedShippingExempt)
{
// If the business unit is UK, disable the shipping method box if country is changed to anything else
// If the business unit is US, disable the shipping method boxes if country is changed to anything else
stateChange($("State" + shipgroup), shipgroup)
disableExpress($('Country' + shipgroup),shipgroup,isUpgradedShippingExempt)
}
what are the dollar symbols? Are they ajax related ?
(Thank you)
The dollar symbol usually found on regular expressions (eg. as back-reference for a match found in a string ).
Here is a function named: $ and used to getElementById() (as already reported)
(search the code for a function with this name)
Cheers!
Kostas
Last edited by Kostas Zotos; 07-16-2008 at 02:14 PM.
usually, people use $ for two reasons (as far as i know, please correct me if wrong)
1) able to port to a PHP script
2) jQuery's convention of using $ for function / var name.
Prototype had it first (their $ function is quite handy, it accepts either id strings or elements and returns an array). Everyone else thought it was a good idea so copied it.
Great wit and madness are near allied, and fine a line their bounds divide.
There are 27 letters in the alphabet as far as JavaScript is concerned. a-z and $. Anywhere you can use a letter in JavaScript you can use $ as that letter. The only place where it has a special meaning beyond whatever your code defines it to mean is where it appears in a regular expression.
You can always define
function $() {alert('you are so smart');}
and then every reference to $() in your code will run that function. If you do define a function with a single letter name then that function can do whatever you want it to do. Any special meaning for such a function will be determined by which library of functions you use with your code (if any).
Bookmarks