Add to a css class using JQuery

后端 未结 6 2213
不知归路
不知归路 2020-12-11 03:14

Is it possible to add/update a css class using JQuery.

I know I can add css to a DOM element using this add css rule using jquery, but I would like to add/remove fro

6条回答
  •  悲哀的现实
    2020-12-11 04:01

    You can do this by using the addClass and removeClass functions in jquery. Add the class like this:

    $("#button1").click(function(){
       $(#the_div).addClass('myClass');
    });
    

    Then you can remove it like this:

    $("#button2").click(function(){
       $("#the_div").removeClass('myClass');
    });
    

    Your CSS properties should be defined in ".myClass".

提交回复
热议问题