How to apply !important using .css()?

后端 未结 30 3025
情深已故
情深已故 2020-11-21 07:06

I am having trouble applying a style that is !important. I’ve tried:

$(\"#elem\").css(\"width\", \"100px          


        
30条回答
  •  难免孤独
    2020-11-21 07:38

    I had the same problem trying to change a text color of a menu-item when "event". The best way I found when I had this same problem was:

    First step: Create, in your CSS, a new class with this purpose, for example:

    .colorw{ color: white !important;}
    

    Last step: Apply this class using the addClass method as follows:

    $('.menu-item>a').addClass('colorw');
    

    Problem solved.

提交回复
热议问题