jQuery遍历以找到父母的父母 [英] jquery traversing to find a parent's parent

查看:58
本文介绍了jQuery遍历以找到父母的父母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML:

<li class="comment">
<div class="p_comm">
 <div class="avatar"><img src="/img/1.jpg"></div>
 <div class="c_auth">author<a class="del" title="delete it!" rel="19">x</a></div>
 <div class="c_cont w">what ever</div>
 <div class="c_time">12-23 13:22:15</div>
</div>
</li>

我想在本节中找到相对于<a>的父li.我找不到执行此操作的功能.我试过prev(),parentsUntil()他们没有一个能做到这一点.目前,我必须使用$(this).parent().parent().parent()才能到达<li>.是否可以直接找到父<li>的函数?

I want to find the parent li relative to the <a> in this section. I can't find a function to do this. I've tried prev(),parentsUntil() none of them can do this. Currently i have to use $(this).parent().parent().parent() to reach <li>. Is there a function to find parent <li> directly?

推荐答案

或者这样:

$(this).parents('li');

这篇关于jQuery遍历以找到父母的父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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