Why doesn't the .selector property in jQuery save the valid selector value?
Assuming I have some HTML similar to this:
<div class="fooContainer"> <div class="barContainer"> <a href="#">foo-bar</a> </div> </div> If in the script my entry point is an anchor and I need to go into a div with the fooContainer class, I can do this:
var $fooContainer = $("a").parents(".fooContainer"); This works fine since $fooContainer now contains an element reference in the DOM.
When I now print the selector value as follows:
console.log($fooContainer.selector) I get the value a.parents(.fooContainer) .
I got the impression that the selector property returned a string, which itself would be the actual value of the selector.
This is not the case when trying to use it as a selector, for example:
$("a.parents(.fooContainer)") Unable to 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 this is not what, you can use the
selectorproperty for?
I tried to find jQuery documentation for information, but could not find anything related to this property.
You can read the source code easily, but what is not documented in the API for viewing is internal and private.
By definition.
So, this is an implementation detail and a property that you really should not try to use, because there is no guarantee, either for future versions, or for any use that you can imagine today.