Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's how I'd do that:</p> <pre><code>(function($) { // this object is available only inside of this function var methods = { init:function(options){ if(typeof options =="object") settings = $.extend(settings,options); return this.each(function(){ methods._someFunction(); // all values are available here by private settings object alert(settings.someParam); $(this).keyUp(function(){ methods._someOtherFunction(); }); }); }, _someFunction:function(filterText) { settings.someParam = "something"; }, _anotherFunction:function(filterText) { settings.someOtherParam = "something"; } } // that one too var settings = { someParam:null, someOtherParam:null } $.fn.filterGroup = function( method ) { // second condition here will disable calling functions starting from "_". // ex. `$(selector).filterGroup('_someFunction');` will return error if( methods[method] &amp;&amp; method[0]!=="_" ) return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); else if ( typeof method === 'object' || ! method ) return methods.init.apply( this, arguments ); else $.error( 'Method ' + method + ' does not exist on jQuery.tooltip' ); }); })(jQuery); </code></pre> <p>Things to note:</p> <ol> <li><code>this</code> in jQuery (especially plugins) reference to the object on which the plugin was called. Therefore <code>this.html()</code> will return contents of <em>this</em> object;</li> <li>So, as I wrote above you should not retreive data from <code>$(inputTextField).val()</code>, but instead call your plugin for those objects like: <code>$(inputTextField).filterGroup()</code>, and then in <code>init()</code> reference to their value as <code>this.val()</code> or <code>$(this).val()</code> if previous won't work for some reason;</li> <li>If you're going to store more then one object's data in settings better make other object called <code>data</code> which would be the list of all element's data :) ;</li> <li>More: <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">http://docs.jquery.com/Plugins/Authoring</a> ;</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload