Remy Sharp's post is confusing unless you read it carefully in my opinion. The value of this never changes. In the example you specified, there were 2 uses of this . As a DOM element in an event:
$('a').click(function() { alert(this.tagName); });
and wrapped as a jQuery object in an event:
$('a').click(function() { alert($(this).val()); });
If you carefully read the 2 snippets above, you will notice that this never changes value. It always refers to a DOM element. The difference is how it is used.
In jQuery, by default, this refers to the DOM element (not the jQuery object) that raised the event. In the second code snippet above, there is still the same DOM element, only it is wrapped in a jQuery element, wrapping $() around it. Like any argument in the jQuery constructor, passing this to the constructor will convert it to a jQuery object.
I think there is confusion when Remy starts talking about jQuery plugins in the same article as jQuery events. JQuery plugins are something that people rarely write and often use. When writing a jQuery plugin, you work in the context of a prototype jQuery object. In this case, you use the word this to refer to the plugin you are writing. In normal use cases, you will not often write plugins, so this is a much less common scenario. If you are not using a plugin, you cannot use this to refer to a jQuery object.
In JavaScript, the this refers to the current instance of an object in JavaScript. When using JavaScript in the prototype, it refers to the prototype instance. Depending on the browser when using a non-jquery-related event model, this also applies to the DOM element. Since some browsers (Internet Explorer) do not treat this as a DOM element in an event, this makes it difficult to work with events. To get around this, jQuery does some JavaScript magic that always makes this reference to the DOM element that raised the event. This is (one of many) reasons to use the JavaScript framework instead of rolling around on your own.
Dan herbert
source share