0

I have a frame and dynamically applying the 'header' class to the frame. It is working fine but need to add '!important' at the end of each css property.

I applied in the following way but not working.

var divblock = '.header';
$('#frame').contents().find('header').addClass('header');

$('#frame').contents().find(divblock).css({
    'color': objProp.css[pageSection]['color']+ '!important',
    'background-color': objProp.css[pageSection]['background']+'!important',
    'font-size': objProp.css[pageSection]['font-size']+'!important'
}); 
5
  • Adding !important is not possible with jQuery .css, you have to use it like setAttribute("style", "width: 12px !important"); Plain JS Commented Aug 11, 2015 at 12:09
  • @abhi Nope. It can be done with jquery. .css(property,value,priority) Commented Aug 11, 2015 at 12:10
  • @RajaprabhuAravindasamy It never worked for me, so I used the setAttribute method only. Commented Aug 11, 2015 at 12:13
  • THIS answer may help Commented Aug 11, 2015 at 12:21
  • 1
    @RajaprabhuAravindasamy there is no overload with those parameters in css-function: api.jquery.com/css Commented Aug 11, 2015 at 12:32

1 Answer 1

1

We can't add the !important using jQuery but you can override the style like as follow.

// CSS styles 
.header{
  color:red;
 }

.importantHeader{
   color: black !important;
}

//script

$('#frame').contents().find('header').addClass('imporatantHeader');

Not this but you can use same class number of times and for this you have to just write one line of code jQuery Code.

This called reusable.

Good Luck ['}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.