最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - can i add css with !important , only using jquery - Stack Overflow

programmeradmin2浏览0评论

hi i am using jquery

i want to add css color with important property to a label

i am currently trying it by

 jQuery(this).css('color','green !important')

with out using a class

like

label_class
{
    background-color:#f2f2f2 !important;
}

and using like

jQuery(this).addClass('label_class');

can i use only jquery to do this , please help

hi i am using jquery

i want to add css color with important property to a label

i am currently trying it by

 jQuery(this).css('color','green !important')

with out using a class

like

label_class
{
    background-color:#f2f2f2 !important;
}

and using like

jQuery(this).addClass('label_class');

can i use only jquery to do this , please help

Share Improve this question edited Aug 2, 2012 at 8:15 Charles 51.5k13 gold badges106 silver badges144 bronze badges asked Aug 2, 2012 at 7:56 Kanishka PanamaldeniyaKanishka Panamaldeniya 17.6k31 gold badges127 silver badges195 bronze badges 1
  • 1 possible duplicate of How to include !important in jquery – Trump Voters Deserve Damnation Commented Aug 2, 2012 at 8:08
Add a ment  | 

2 Answers 2

Reset to default 3

Yes its not that hard, but you should try avoid using !important all the time.

$("#tabs").css("cssText", "height: 650px !important;");

Heres a link to similar question How to include !important in jquery

Hope this helps :)

You should never need to do this. The !important flag indicates that the style should take precedence. With jQuery, you are applying the style inline to the element and therefore it already has the highest precedence.

Note that if you are using !important, you are probably doing something wrong. Consider restructuring your CSS selectors to ensure you don't need it.

发布评论

评论列表(0)

  1. 暂无评论