JQuery.selector property removed, workaround?

I am trying to use a selector to call the current script, but, of course, the property I need has been removed for some reason.

Is there a workaround for this? Here is basically what I want to accomplish:

(function($) { $.fn.myplugin = function(options) { return this.each(function() { console.log($(this).selector); }); } }(jQuery)); //Somwehere else: $('.theClassISelected').myplugin(); //Should console.log('.theClassISelected') 

I need to see .theClassISelected (or some form of the original selector that I used to call the function) in the console, but since the selector property has been removed from jQuery, this is no longer possible.

I do not understand why this was removed. I have been looking for this problem for a long time, and all I see is StackOverflow answers from 2011-2012 recommending the selector property. I think it was useful at some point, but no more?

+7
source share
1 answer

From the jQuery documentation:

Plugins that must use the selector must have a transmitter in the selector as part of the plugin arguments during initialization.

http://api.jquery.com/selector/

As an aside, the docs also mention that the selector property was not reliable, because "since subsequent workarounds could change the set."

+3
source

All Articles