How to apply !important using .css()?

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

    const elem = $("#elem");
    elem[0].style.removeAttribute('width');
    elem[0].style.setProperty('width', '100px', 'important');
    

    Note: Using Chrome may return an error such as:

    elem[0].style.removeAttribute is not a function

    Changing the line to use the .removeProperty function such as to elem[0].style.removeProperty('width'); fixed the issue.

提交回复
热议问题