dilwaria dilwaria - 2 months ago 5
jQuery Question

What is the difference between $ , this and $(this) in javascript fundamentals?

What is the difference between $ , this and $(this) in javascript fundamentals?

Also I want to know about their usage

Answer

In short (assuming jQuery is included, of course):

  • $ is a variable of window containering the jQuery library itself.
  • this is a variable containing a DOM element.
  • $(this) casts the element this to an jQuery object.

So basically you can't talk about a difference. The one is the whole library itself and the other is just using the library ...

Another example to be clear:

var $ = function(param) {};
var elem = this;

$        // the library
elem     // the element
$(elem); // the usage