开发者

IN Jquery , how do I go up a parent node?

I just want 开发者_StackOverflow中文版to go up a parent node, so I can do a .find inside that parent node.

In a sense, I want to .find a sister.


$('el').siblings('li');

or

$('el').parent().find('li');


To traverse to a closest possible parent node

$('.someclassname').closest('.parentclassname')

And to find a node inside that

$('.someclassname').closest('.parentclassname').find('.findwhatever')

If the node you are finding is on same level of your current node say

<div class="testcls">
  <p class="child1">child1</p>
  <p>child2</p>
</div>

In above child2 is sibling of child1 so you can find such siblings using

$('child1').siblings();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜