1

Has someone knows why this four lines of jquery code:

var newFontSize = settings.FontSize + 'em !important';
_log(newFontSize);

$('div[data-role="section"]').css("font-size", newFontSize);
_log($('div[data-role="section"]').css( "font-size"));

returns this messages in the output:

1.1em !important
14px

I have been watching my code for hours and I do not know where is my mistake.

Thank you in advance,

  • how this `14px` is getting assigned to that `div`? Is it through `.css` file? If so can you show us that css code as well? – vijayP Nov 01 '15 at 11:31
  • 2
    You cannot add `!important` using `jQuery` `css` function. Refer the jQuery bug [11173](http://bugs.jquery.com/ticket/11173). Note the bug is closed as `wontfix`. See [this](http://stackoverflow.com/a/8894528/643318) answer for an alternate function to do this. – Taleeb Nov 01 '15 at 11:58
  • In addition to the answer: you're adding inline styles which should, by default, override anything declared in the stylesheet. In which case, why are you trying to add !important? It suggests you're doing something incorrectly in the stylesheet. – DanCouper Nov 01 '15 at 14:06

1 Answers1

0

Yes, the problem is that you can't add !important wiht jQuery. A work around could be: created classes in your stylesheet and then add / remove the classes

$('div[data-role="section"]').removeClass(x).addClass(y);
S. F.
  • 206
  • 4
  • 14