How to change css property using jquery with this code

后端 未结 3 770
天涯浪人
天涯浪人 2021-02-14 19:21

\"#business\" is currently set to background: #323232; How can I change it to #000; after I click on \"#business\" and back to 323232 once the menu is closed?

$         


        
3条回答
  •  孤街浪徒
    2021-02-14 19:59

    You can use the css method to change a CSS property (or multiple properties if necessary):

    $("#business").click(function(event){
        jQuery.fx.off = true;
        $("#businessmenu").toggle("");
        $(this).css("background-color", "#000");
        event.stopPropagation();
    });
    $('html').click(function() {
        $("#businessmenu").hide();
        $("#business").css("background-color", "#323232");
    });
    

    Note that I've combined the 2 event listeners you had bound to #business as it's makes no difference to just bind the one.

    As a side note, is there a reason you are passing an empty string to hide? That shouldn't be necessary.

提交回复
热议问题