jQuery多个parent()调用

我有这个jQuery:

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

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

 

有人能指出我正确的方向让我的jQuery更精简吗? 上面给出的结构被多次复制,因此使用类和ID是不可能的。

您可以使用类(或任何其他可选属性)和.closest()来声明您想要的父级,如下所示:

  

而对于脚本:

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

你可以使用.parents( [ selector ] ) 这里是一个链接

它将遍历多个父母。

使用parents()

 $(this) .parents('selector for the parent you need to look in') .find(".license_tooltip") .stop(true, true) .fadeIn(200);