jQuery:在嵌套元素中找到parent()* n? [英] jquery: find parent()*n in nested element?

查看:135
本文介绍了jQuery:在嵌套元素中找到parent()* n?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我永远找不到答案的问题.

the question I could never find an answer for.

想象一下,我在div中具有以下结构:

imagine I have a rather the following structure inside of a div:

<div class="BOX">
    <ul class="menu" role="navigation">
        </li><li><a class="btn" href="#">edit</a></li>
        <li><a class="btn" href="#">manage</a></li>
        <li><a class="btn deleteBtn" href="#">delete</a></li>
    </ul>
</div>

我要find() div.BOX when我单击a.deleteBtn.由于我的页面上有多个div.BOX,因此始终需要使用$(this)查找它.

I want to find() div.BOX when I click on the a.deleteBtn. Since I have multiple div.BOX'es on my page I always need to find it with $(this).

因此我可以轻松地使用trigger.parent().parent().parent()在deleteBtn-ClickHandler内时选择元素,但这看起来不太好.有没有更清洁,更好的方法呢?

so I could easily use trigger.parent().parent().parent() to select the element when inside of the deleteBtn-ClickHandler, but this doesn't look very nice. Is there a cleaner and better way to do so?

谢谢.

推荐答案

尝试一下:

$(this).closest("div.BOX")

这篇关于jQuery:在嵌套元素中找到parent()* n?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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