Reputation: 20438
I'm trying to decipher the following line of code
.find('> li ul:visible')
And I cannot figure out what '>' achieves. I'm having trouble searching the documentation
Upvotes: 0
Views: 168
Reputation: 150273
>
Is a child selector, thus it finds the visible ul
that is a descendant of li
which is a direct child of the selector...
Child selector
Description: Selects all direct child elements specified by "child" of elements specified by "parent".
So when you >
is in a find
function, the parent is the element in the selector.
BUT!! it's deprecated, as the docs says:
Note: The
$("> elem", context)
selector will be deprecated in a future release. Its usage is thus discouraged in lieu of using alternative selectors.
Upvotes: 0
Reputation: 2736
What it does is find all direct children of the current element based on the selector provided.
Let's say we have
<ul id="example">
<li>Item 1</li>
<li>Item 2</li>
<li>
<ul>
<li>Item 3</li>
</ul>
</li>
</ul
If I searched for $("#example").find('>li')
I would only find the two li's with Item 1 & Item 2. Since the <li>
with Item3 is not a direct child from our target <ul>
it is not matched.
Upvotes: 1
Reputation: 5251
Its a definition for a child selector, the same as css e.g. see jQuery selector AND operator for how to select rows within a table body that aren't in the header.
Your example is finding a child element that is a list element
See also the API documentation http://api.jquery.com/child-selector/ as suggested by @bzlm
Upvotes: 0