简体   繁体   English

hasClass()不起作用

[英]hasClass() doesn't work

Just wondering why it doesn't alert ? 只想知道为什么它不警报?

I am sure my variables are right and exist in this context too. 我确信我的变量是正确的,并且在这种情况下也存在。

if ($(".side-nav .nav").hasClass("features").toString()) {
    alert('test');
}

To test it I have tried to add the ! 为了测试它,我尝试添加! in front and a class that doesn't exist : 在前面,一个不存在的类:

if (!$(".side-nav .nav").hasClass("whatever").toString()) {
    alert('test');
}

and it works. 而且有效。

remove toString() 删除toString()

 if ($(".side-nav .nav").hasClass("features")) {
        alert('test');
    }

It's like you are converting a boolean to a string? 就像您要将布尔值转换为字符串一样?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM