[ACCEPTED]-jQuery select elements on 1st "level-css-selectors
Accepted answer
$("#BaseElement").children("span");
or
$("#BaseElement > span");
See jQuery selectors and children()
.
0
In the jQuery API, when it refers to 'descendants' it 5 means all levels, and when it refers to 4 'children' it means only the first level
this 3 will get you all first level children (in 2 your example the first p, div, 2 spans, and 1 last p)
$('#BaseElement > *')
Also refer to What is the difference direct descendent (>) vs. descendant in jQuery selectors? for differences between space 4 and > in selectors. With space equals to 3 find() and > equals to children(). In other 2 words, the following pairs are equivalent,
$("#BaseElement").children("span");
$("#BaseElement > span");
Get 1 all children plus their descendants:
$("#BaseElement").find("span");
$("#BaseElement span");
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.