I am trying to develop the plugin using jquery-boilerplate-v3.1 and is confused between "this" and "$ (this)," in the plugin
. .. $ .fn [pluginName] = function (option) {// alerts ($ (this) .toSource ()); ($ .data (this, 'plugin_' + pluginname)) {$. Return the data (this, 'plugin_' + plugin name, new plugin (this, option));} ; }; It looks like the new plugin (this, option) does not return the element inside the plugin. Protocol Reference Instead, it has been modified in the plugin ($ (this), option) . Example $ (function () {$ ('# container'). MyPlugin ();}); I can not access it without using $ (this) as the parameter. In the plugin, .toSource () empty object ({}) . Am I correcting it by modifying $ (this) or how can I use #container with the this parameter. TIA
In the plugin, this refers to the object of the jQuery plugin , But within the callback for this.each () , this refers to the DOM element in each object. So, yes, you need $ (this) to get that element inside a loop for a jQuery object.
Comments
Post a Comment