繁体   English   中英

在 jQuery 中添加或删除 class

[英]Add or Remove class in jQuery

This looks awkward but when I'm trying to add any class or remove any class using jQuery it's not working, Instead of adding or removing class I tried with the alert window, in that case, it's working fine. 谁能告诉我为什么我无法添加或删除任何 class?

$('#sign').click(function(){
    alert("I'm working");
    $('#signup').ready(function(){
        $(this).addClass('hidden');
    });
});

这是我尝试过的代码, #sign是侧边栏或导航栏中的 ID。 当我单击该链接时,它会转到 ID 为#signup的部分。 在本节中,我希望添加或删除 class。

参见: https://api.jquery.com/ready/

$('#signup').ready(...)似乎不适用。 该页面已加载,因此您无需等待 DOM 准备好。 只需删除该包装并直接操作 class :

$('#sign').click(function(){
    alert("I'm working");
    $('#signup').addClass('hidden');
});

我假设您正在尝试处理单击和更改不同元素上的类(尽管名称相似)。

暂无
暂无

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

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