[jQuery] Re: Need help learning
this refers to different objects depending on where we are in the code... (function($) { $.fn.myPlugin = function() { // here this refers to the jQuery object on which the myPlugin method was called upon this.each(function() { // here this refers to the matched elements in the jQuery object... in your example, you matched every DIV element, so this refers to each node in the DOM tree that has type = ELEMENT_NODE nodeName = DIV alert(this.id) $.get(return.php,function(data) { // here this refers to the options object for the AJAX request you may print it out with this code: for (prop in this) { $(div).append(prop + = + this[prop] + br); } alert(this.id); //do something with this the data }); }); return this; }; })(jQuery);
[jQuery] Re: Need help learning
If you want to manipulate with the DIV inside the $.get function, you can declare a local variable and put the reference to DIV in it... (function($) { $.fn.myPlugin = function() { this.each(function() { alert(this.id); var that = this; $.get(return.php,function(data) { // now this is that alert(that.id); //do something with this the data }); }); return this; }; })(jQuery); You don't have to call the variable that, but it's a nice name, isn't it? :)
Re: [jQuery] Re: Need help learning
Thank you, you have help out so much On Jan 6, 2010, at 6:14 PM, Šime Vidas wrote: If you want to manipulate with the DIV inside the $.get function, you can declare a local variable and put the reference to DIV in it... (function($) { $.fn.myPlugin = function() { this.each(function() { alert(this.id); var that = this; $.get(return.php,function(data) { // now this is that alert(that.id); //do something with this the data }); }); return this; }; })(jQuery); You don't have to call the variable that, but it's a nice name, isn't it? :)