如何使用jquery到达叔叔 [英] How to reach the uncle using jquery

查看:114
本文介绍了如何使用jquery到达叔叔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < div id =grandfather> 
< div id =uncle>< / div>
< div id =father>
< div id =me>< / div>
< / div>
< / div>

我在$(#我),我想选择我的叔叔, $ {pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ).next(#uncle)
$(#me)。prev(#uncle)

如何?

解决方案

您可以使用 $。 $ c>和 $。prev 假设你的叔叔总是在你父亲之上:

  $(this).parent()。prev(); // where'this'is #me 


$ b $你也可以一路走到你的祖父身边,从那里找到叔叔:

  $(this) .parents(#grandfather)。find(。叔叔); 

或者你可以搜索你父亲的兄弟姐妹:

  $(this).parent()。siblings(#uncle); 

我会鼓励你r请参阅遍历部分的jQuery API,了解各种其他方法。


<div id="grandfather">
  <div id="uncle"></div>
  <div id="father>
    <div id="me"></div>
  </div>
</div>

I am at $("#me") , and I want to select my uncle, using stuff like :

 $("#me").find("#uncle")
 $("#me").next("#uncle")
 $("#me").prev("#uncle")

How ?

解决方案

You could use $.parent and $.prev assuming your uncle is always above your father:

$(this).parent().prev(); // where 'this' is #me

You could also go all the way up to your grandfather, and find uncles from there:

$(this).parents("#grandfather").find(".uncles");

Or you could search your father's siblings:

$(this).parent().siblings("#uncle");

I would encourage you to read the Traversing portion of the jQuery API for various other methods.

这篇关于如何使用jquery到达叔叔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆