I would like to write something like this
$("div.banana .for aside.scale").yellowify();
$.fn.yellowify = function () {
this.css("color","yellow");
alert($(this).selector);
});
which warns
div.banana .for aside.scale
The question is very similar to this one , however the poster wants to get the DOM structure by scanning the parents of the selector or something like that. I just want the selector to be as it is, without any additional classes or identifiers. I want it to be the same as there, in the first line.
jQuery is used for this property .selector, but it is deprecated in 1.7 and removed in 1.9 ( or is it there? - thanks to Ted. UPDATE .selector will only be removed in jQuery 3.0 !). Status of documents :
, , . , "foo" $.fn.foo = function (selector, options) {/* */};, , , $( "div.bar" ).foo( "div.bar" , {dog: "bark" }); "div.bar" .foo().
, . , - ? - ?
, , , , - , , , :
$.fn.yellowify = function () {
var css = $(this).selector + "{color: yellow;}";
css += $(this).selector + " .child {color: red;}";
$("<style>").html(css).appendTo("head");
});
.