admin管理员组

文章数量:1022670

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.

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.

本文标签: javascriptcan i add css with importantonly using jqueryStack Overflow