Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Inside the function of a jQuery plugin function:</p> <pre><code>this.selector </code></pre> <p>will be the original selector passed to the original jQuery object. I can't tell for sure, but this may be deprecated in the latest versions of jQuery, though it is still present in jQuery 2.0.2.</p> <p>Working demo here:</p> <p><a href="http://jsfiddle.net/jfriend00/JczB9/" rel="nofollow">http://jsfiddle.net/jfriend00/JczB9/</a></p> <pre><code>$.fn.test = function() { // this.selector contains #test from the original jQuery selector }; var item = $("#test"); item.test(); </code></pre> <hr> <p>If you're trying to get access to the jQuery instance (to get the original selector) from a public method on your jQuery plugin such as <code>$('#test').pluginName.publicFunction();</code> in your example, you can't. </p> <p>The selector is a property of a jQuery instance only so only methods of a jQuery instance or functions who have a reference to a jQuery instance are going to be able to access the <code>.selector</code> property. </p> <p><code>$('#test').pluginName</code> is a static function object (e.g. there's only one of them) - it isn't a jQuery instance so <code>$('#test').pluginName.publicFunction()</code> doesn't have access to the properties of <code>$('#test')</code> and thus can't get to the selector. </p> <p>If I understood why you were making public functions on your jQuery plugin and what you were trying to do with it, I might have an alternate solution for you.</p> <p>For example, your <code>publicFunction()</code> could itself be a jQuery plugin method and then you could use chaining like <code>$('#test').pluginName().publicFunction()</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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