开发者

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

开发者 https://www.devze.com 2022-12-24 22:51 出处:网络
I just want 开发者_StackOverflow中文版to go up a parent node, so I can do a .find inside that 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

精彩评论

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