Example 1
To use the selector used in your plugin, use:
this.selector
Example:
$.fn.myPluginMethod = function(myValue) { $(this.selector).html(myValue); } $("#content").myPluginMethod("Hello World");
Demo Screenshot: http://jsfiddle.net/nJeeH/
Example 2
The only other solution is to create a faux myPlugin method that simply returns a jquery object to support the chain, but that does not stop you from just making $("#content").myMethod("Hello World"); instead of this.
$.fn.myPlugin = function(myValue) { return this; } $.fn.myMethod = function(myValue) { this.each(function() { $(this).html(myValue); }); } $("#content").myPlugin().myMethod("Hello World");
Demo Screenshot: http://jsfiddle.net/nJeeH/1/
source share