使用jQuery nearest()方法和类选择器 [英] Using jQuery closest() method with class selector

查看:99
本文介绍了使用jQuery nearest()方法和类选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(this).closest(".fieldfilters");

这对我没有任何回报。 HTML结构如下所示:

This returns nothing for me. The HTML structure is like this:

<div class="fieldfilters" >
    <div class="filtri_ul_list">
        <ul>
            <li> <a></a></li>
        </ul>
    </div>
</div>

$(this)< a取代; 。据我所知最近的遍历DOM并找到最接近的匹配。选择器是一个类有问题吗?为什么这不起作用?

$(this) is the <a>. As far as I understand closest traverses the DOM up and finds the closest match. Is there a problem with the selector being a class? Why doesn't this work?

推荐答案

你对.closest()的使用完全没问题。

Your usage of .closest() is perfectly fine.

$(this).closest(".fieldfilters");

您问题的最可能原因是$(this)不是您认为的那样。
检查你的上下文,看看这是什么'。

The most probable cause of your problem is that $(this) is not what you think it is. Check your context to see what 'this' really is.

这篇关于使用jQuery nearest()方法和类选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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