简体   繁体   English

jQuery一键显示隐藏和活动类

[英]jQuery show hide and active class in one button

I have this code and I want to add active class to button .loginhead (to remove and add class when click and when content show and hide). 我有这段代码,我想向按钮.loginhead添加活动类(单击时以及内容显示和隐藏时删除并添加类)。 How I can do that? 我该怎么做?

$(".top .login").hide('', function () {
    $('.loginhead').removeClass("active");  
});

$(".loginhead").show();

$('.loginhead').click(function () {
    $(".top .login").slideToggle();
    $('.loginhead').addClass("active");
}); 

use toggleClass() . 使用toggleClass() If I'm understanding you right. 如果我理解正确的话。 Here's a link to documentation: http://api.jquery.com/toggleClass/ 这是文档的链接: http : //api.jquery.com/toggleClass/

$('.loginhead').toggleClass("active");

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

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