> Here's a rundown on 'this'... > > this - is a JavaScript keyword. Inside a function that is called as a method > of some object, this is a reference to the object in question. But whoever > calls a function can explicitly set this to be any object. In the hover > event handlers (and all jQuery event handlers), this is a reference to the > DOM element that triggered the event. In your code, this is a reference to > the element whose ID is 'rightDiv'. In particular, this is *not* a jQuery > object here. (It's different in an jQuery *plugin* function, i.e. a function > that is added to jQuery.fn or jQuery.prototype. In those functions, this is > a reference to the jQuery object, not to a DOM element.) > > $(anyDomElement) or jQuery(anyDomElement) - creates a jQuery object > containing the single DOM element referenced in the call. As a result: > > $(this) or jQuery(this) - if this is a DOM element, then $(this) or > jQuery(this) creates a jQuery object containing that DOM element, so you can > call jQuery methods such as your .css() call. > > $ (this) or jQuery (this) - the space is not significant, so it means the > same as $(this) or jQuery(this). I personally consider it a bad coding > practice to put a space between a function name and the opening paren. > > $.this - is invalid because this is a JavaScript reserved word. $.this is > attempting to use "this" as the name of a property of the $ object. Some > browsers may allow it anyway, for example Firefox allows $.this - but no one > should ever use it. > > $.(this) - is invalid syntax. It's unlikely that any browser would ever let > you use it. > > $this - is an ordinary variable name with no special meaning whatsoever. It > can be used in the same way as any other variable name. > > Note that $ is not a magic character. It's treated just like a letter of the > alphabet in JavaScript function and variable names. > > -Mike
That has to be the best explanation I've heard in a long long long time. You've have really helped de-mystify the $this variable. Thanks a million!