[ACCEPTED]-jQuery select elements on 1st "level-css-selectors

Accepted answer
Score: 57


$("#BaseElement > span");

See jQuery selectors and children().


Score: 14

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 > *')
Score: 3

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 > span");

Get 1 all children plus their descendants:

$("#BaseElement span");

More Related questions