$this vs $(this) in jQuery

javascript, jquery

Solution

`$this` is just an ordinary variable. The `$` character is a valid character in variable names, so `$this` acts the same as any other non-reserved variable name. It's functionally identical to calling a variable `JellyBean`.

Problem

I've seen some discussions on SO regarding `$(this)` vs `$this` in jQuery, and they make sense to me. (See discussion here for an example.) But what about the snippet below, from the jQuery website plugin tutorial showing how chainability works? ``` (function ($) { $.fn.lockDimensions = function (type) { return this.each(function () { var $this = $(this); if (!type || type == 'width') { $this.width($this.width()); } if (!type || type == 'height') { $this.height($this.height()); } }); }; })(jQuery); ``` What does `$this` represent above? Just when I think I have it figured out ...

Original source

Related problems