title: Get exact selector in jQuery / alternative to .selector
body: <p>I wish I could write something like this</p>
  
  <pre><code>$("div.banana .for aside.scale").yellowify();
  
  $.fn.yellowify = function () {
      this.css("color","yellow");
      alert($(this).selector);
  });
  </code></pre>
  
  <p>which would alert</p>
  
  <pre><code>div.banana .for aside.scale
  </code></pre>
  
  <p>The question is very similar to <a href="https://stackoverflow.com/questions/2420970/how-can-i-get-selector-from-jquery-object">this one</a>, however, there the poster wants to retrieve a DOM structure by scanning parents of the selector or something like that. I simply want the selector <em>as is</em>, without any additional classes or IDs. I want it <em>exactly</em> as it's there in the first line.</p>
  
  <p>jQuery used to have this <code>.selector</code> property, but it has been deprecated in 1.7 and removed in 1.9 (<a href="http://jsfiddle.net/vz3xc3se/" rel="nofollow noreferrer">or has it?</a> - thanks Ted. <strong>UPDATE</strong> <code>.selector</code> will only <a href="https://github.com/jquery/jquery/issues/2355#issuecomment-106043451" rel="nofollow noreferrer">be removed in jQuery 3.0</a>!). <a href="https://api.jquery.com/selector/" rel="nofollow noreferrer">The docs</a> state:</p>
  
  <blockquote>
    <p>Plugins that need to use a selector string within their plugin can
    require it as a parameter of the method. For example, a "foo" plugin
    could be written as $.fn.foo = function( selector, options ) { /*
    plugin code goes here */ };, and the person using the plugin would
    write <strong>$( "div.bar" ).foo( "div.bar", {dog: "bark"} ); with the
    "div.bar" selector repeated as the first argument of .foo()</strong>.</p>
  </blockquote>
  
  <p>But I think that that's incredibly ugly and not user-friendly at all. Is there an alternative possible that doesn't require any action on the user's side? I.e. without needing any additional arguments?</p>
  
  <hr>
  
  <p>For those who are curious, ideally I want my plugin to be able to echo styles for the specific element, something like this, but obviously much more complicated:</p>
  
  <pre><code>$.fn.yellowify = function () {
      var css = $(this).selector + "{color: yellow;}";
      // I can add rules for specific elements now as well
      css += $(this).selector + " .child {color: red;}";
      $("&lt;style&gt;").html(css).appendTo("head");
  });
  </code></pre>
  
  <p>Together with arguments, this allows me to have a far reach with my plugin.</p>