开发者

jquery select all elements in just the current element and not child element

I've done a few things such as selecting all children of an element, all parents of an element, first child etc.. but this is a little tricky.

I have the structure somewhat similar to this:

<div class="body">
    <a href="something">Something</a>
    <small>
          <a href="something-else开发者_运维技巧">Something-else</a>
    </small>
</div>

and this structure is repeated a whole lotta times.

I need to select all <a> elements found only in the top level div.body and ignore all <a> that's found in the <small> element.

How do I go around with this please?

thanks,.


Simply use the child selector rather than the descendant selector:

$('div.body > a');


The child selector only selection direct elements of a parent element, so:

$('div.body > a')

should do the trick


Use the child selector:

$("div.body > a")

A > B means: "B is a immediate child of A", whereas
A B means: `B is a (not strictly immediate) child of A.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜