jQuery: What is ‘this’ and ‘$(this)’

There are two concepts this and $(this) when inside a jQuery method’s anonymous callback function:

  • this is a reference to the current DOM element.
  • $(this) turns this into a jQuery object and exposes jQuery’s methods.

A jQuery object is nothing more than a beefed-up array of DOM elements.

A example demonstrating the uses of this and $(this) to get an anchor’s href value. These statements are equivalent:

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA