Assuming I have HTML similar to this:
<div class="fooContainer">
<div class="barContainer">
<a href="#">foo-bar</a>
</div>
</div>
If in script my entry point is the anchor and I need to get to the div with the class fooContainer I can do this:
var $fooContainer = $("a").parents(".fooContainer");
This works perfectly fine as $fooContainer
now holds the reference to the element in the DOM.
When I now print out the selector
value like this:
console.log($fooContainer.selector)
I get the value a.parents(.fooContainer)
.
I was under the impression that the selector
property returned a string which itself would be a valid selector value.
This is not the case though as when trying to use it as a selector like this:
$("a.parents(.fooContainer)")
It cannot find a match in jQuery 1.7.2.
And in the latest jQuery 1.8.x it even throws an exception: Error: Syntax error, unrecognized expression: a.parents(.fooContainer)
selector
property for?I tried searching the jQuery documentation for information but was not able to find anything related to that property.
You can easily read the source code but what isn't documented in the browsable API is internal and private.
By definition.
So this is an implementation detail, and a property you really shouldn't try to use as there is no guarantee, neither for the future versions nor for any use you might imagine today.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With