jQuery多个parent()调用 [英] jQuery multiple parent() calls

查看:103
本文介绍了jQuery多个parent()调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个jQuery:

I have this jQuery:

$(this).parent().parent().find(".license_tooltip").stop(true, true).fadeIn(200);

$(this)对象嵌套在两个div中,如下所示:

The $(this) object is nested within two divs like this:


<div>
    <div>
        <a href="">$(this) object</a>
    </div>

    <div>
        <a href="">object to fade in</a>
    </div>
</div>

有人可以指出正确的方向来使我的jQuery更加简化吗?上面介绍的结构被多次复制,因此无法使用类和ID.

Can someone point me in the right direction to making my jQuery more streamlined? The structure presented above is replicated multiple times, so using classes and IDs is impossible.

推荐答案

您可以使用类(或任何其他可选属性)和 .closest() 声明您想要的父级,就像这样:

You can use a class (or any other selectable attribute) and .closest() to claim to the parent you want, like this:

<div class="container">
    <div>
        <a href="">$(this) object</a>
    </div>

    <div>
        <a href="">object to fade in</a>
    </div>
</div>

对于脚本:

$(this).closest(".container").find(".license_tooltip").stop(true, true).fadeIn(200);

这篇关于jQuery多个parent()调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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