How to apply !important using .css()?

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

    We need first to remove the previous style. I remove it using a regular expression. Here is an example for changing color:

    var SetCssColorImportant = function (jDom, color) {
           var style = jDom.attr('style');
           style = style.replace(/color: .* !important;/g, '');
           jDom.css('cssText', 'color: ' + color + ' !important;' + style); }
    

提交回复
热议问题