How do I add a css class to an Div element in JQuery?

前端 未结 4 1391
一整个雨季
一整个雨季 2021-01-28 21:52

How do I add a css class to an Div element in JQuery? I have a DIV with a css class and the div contains a form. After clicking on submit I want the original css class to disapp

4条回答
  •  一向
    一向 (楼主)
    2021-01-28 22:30

    To add a class, use addClass:

    $('#myDiv').addClass("blah");
    

    So upon your submit you can do something like:

    $('#submit').click(function() {
        $('#myDiv').removeClass().addClass("blah");
    });
    

    Calling removeClass with no parameters removes all classes linked to that element. Alternatively, you can call removeAttr("style")

提交回复
热议问题