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)
- Why does the selector property not contain a valid selector value?
- If it doesn't what would one use the
selector
property for?
I tried searching the jQuery documentation for information but was not able to find anything related to that property.
.selector
in the API documentation is probably because it was intended for internal use only. You wouldn't be expected to use it at all, and you won't find it documented anywhere official..selector
being private. If it was only intended for internal use I more than happily stay away from it :) No need to explain internal implementations to me. I would have loved to see any documentation on it though. where do I find that information?