开发者

jquery: find parent()*n in nested element?

开发者 https://www.devze.com 2023-03-27 01:07 出处:网络
the question I could never find an answer for. imagine I have a rather the following structure inside of a div:

the question I could never find an answer for.

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" h开发者_如何学Pythonref="#">delete</a></li>
    </ul>
</div>

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).

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?

thank you.


try this:

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


or you can use $(this).parents('div.BOX')

0

精彩评论

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