jquery表兄弟元素 [英] jquery cousin element
问题描述
我正在尝试找到包含类的最近元素....这是为了找到我当前元素的堂兄..
以下不起作用:
I am trying to locate the closest element that contains a class....this is in an effort to find the "cousin" of the current element that i have.. the following did not work :
$('myelement').closest ('*:has(.class1)').find('class_cousin')
我在<$ c中使用 *
$ c>最近的因为我不确定我要查找的是哪个类型元素,也不知道它是否有任何类或ID(我试图保持一般的插件)
I am using the *
in closest
since I am not sure what type element is the one I am looking for nor do I know if it has any classes or ID (I am trying to keep it general for a plugin)
我知道怎么做吗?
谢谢
any idea how I could do it? thank you
推荐答案
我认为你很接近。这样的事情应该有效:
I think you're close. Something like this should work:
$('myelement').closest(':has(.yourClass)').find('.yourClass')
我认为关键是你正在寻找最近的父母那个有你正在寻找的特定类,然后想找到那个特定的对象。
I think the key is that you're looking for the closest parent that has the particular class you are looking for, then want to find that particular object.
当然,上面的问题是它不一定能找到.yourClass的一个实例。您可以拥有一个包含多个表兄弟对象的父对象。我也不确定上面的查询有多昂贵。可能存在性能问题。
Granted, the problem with the above is that it's not necessarily finding ONE instance of .yourClass. You could have a parent object with multiple cousin objects. I'm also not sure how expensive of a query the above is. There might be performance issues.
这篇关于jquery表兄弟元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!