简体   繁体   English

单击.toggle添加/删除类

[英]click .toggle add/remove class

When i click #tool I want to add the class .spanner to the div #drill . 当我单击#tool我想将.spanner.spanner到div #drill

However when #drill has the class .spanner and #tool is clicked i want the class to be removed? 但是,当#drill具有类.spanner#tool单击时,我要删除该类吗?

Use the toggleClass function: 使用toggleClass函数:

$("#tool").click(function() {
    $("#drill").toggleClass("spanner");
});

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

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