How to apply !important using .css()?

后端 未结 30 2982
情深已故
情深已故 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:30

    You can set the width directly using .width() like this:

    $("#elem").width(100);
    

    Updated for comments: You have this option as well, but it'll replace all css on the element, so not sure it's any more viable:

    $('#elem').css('cssText', 'width: 100px !important');
    

提交回复
热议问题