How to apply !important using .css()?

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

    It may or may not be appropriate for your situation but you can use CSS selectors for a lot of these type of situations.

    If, for example you wanted of the 3rd and 6th instances of .cssText to have a different width you could write:

    .cssText:nth-of-type(3), .cssText:nth-of-type(6) {width:100px !important;}
    

    Or:

    .container:nth-of-type(3).cssText, .container:nth-of-type(6).cssText {width:100px !important;}
    

提交回复
热议问题