> Now that it is laid out in front of me it's pretty obvious, 
> but when you come into the thing cold, these things are not 
> obvious. I think it would be a good idea to explicitly state 
> what the object is, and that $ refers to it (I think that's 
> right ... now I mention it I'm not quite sure if $ is an 
> object reference or an operator ... ) - anyhow just a bit of 
> clarification of the basics.

It's neither of the above. :-)

$ is not an operator. In JavaScript, the $ character can be used in names in
the same way as a letter.

$ is also not a "jQuery object" or a reference to one. at all. It is a
*function* that returns a jQuery object.

A good way to think of the $ function is that it's just like a constructor
function (e.g. Date or Array), except you don't use the "new" operator with
it, you just call it.

Consider this code:

  // Give the $ function a more self-explanatory name
  var createQueryObject = $;

  // Create a query object for a specified query string
  var myQueryObject = createQueryObject('#test');

  // Call a method of the query object
  myQueryObject.hide();

That is the same as:

  $('#test').hide();

Note also that $ and jQuery (used as a name in JavaScript code) are the same
thing. So you could also write this code as:

  jQuery('#test').hide();

Or:

  var myQueryObject = jQuery('#test');
  myQueryObject.hide();

-Mike


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to