Can I use jquery to remove/negate css !important rule?

后端 未结 5 1402
挽巷
挽巷 2020-12-16 12:07

If there is a CSS rule that uses !important, is there a way to remove the !important rule so that I can make further downstream style changes with

5条回答
  •  清歌不尽
    2020-12-16 12:26

    I have tried several methods, but the best results I've obtained by adding the CSS style (!important) in a separate class, then remove with jQuery:

    CSS:

    .important-css-here { display: block !important;}
    

    In jQuery:

    $("#selector").addClass("important-css-here");
    

    then, when I need:

    $("#selector").removeClass("important-css-here");
    

    work like a charm ;-)

提交回复
热议问题