Difference between this and $(this) and when I should use which?
Hello all,
I am confused about when to use this and when to use $(this).
It seems that $(this) is related to jQuery and this is related to jQuery, however, in both case I and case III, this is related to jQuery (if my understanding is correct
).
Thank you
- $('li').each(function(index) {
- alert(index + ': ' + $(this).text()); // case I
- });
- $(document.body).click(function () {
- $("div").each(function (i) {
- if (this.style.color != "blue") { // case II
- this.style.color = "blue";
- } else {
- this.style.color = "";
- }
- });
- });
- (function($){
- $.fn.makeItBlue = function() {
- return this.css('color','blue'); // case III
- }
- })(jQuery);