0

For example, if I have:

<div id="divtochangeFont">
    <p>This will change font size</p>
    <p stlye="font-size: 10px">This will not change font size</p>
</div>

Now I want to resize font with jQuery in all div content. For example, with simple jQuery:

$("#divtochangeFont").css("font-size","16px");

But it changes only in first paragraph. How to override all defined font-size attributes in div?

PS: Scale effect can't be used...

Trick
  • 3,699
  • 11
  • 47
  • 76

5 Answers5

1
$("#divtochangeFont, #divtochangeFont *").css("font-size", "16px");
Andreas Louv
  • 44,338
  • 13
  • 91
  • 116
1
$("#divtochangeFont * ").css({"font-size": "16px","color": "orange"});

you only need to take all children of your div

Aram Mkrtchyan
  • 2,615
  • 3
  • 29
  • 42
0

you could do something like:

$("#divtochangeFont").css("font-size","16px");
$("#divtochangeFont").children().each(function () {
  $(this).css("font-size","16px");
});
tmaximini
  • 8,284
  • 6
  • 45
  • 68
0

Since you're setting the font on the parent div, the child p with a font-size of 10px has precedence for that paragraph. (That's the cascading in CSS.)

What frank blizzard suggests will work. Personally, I'd just change your selector if #divtochangeFont only contains p's.

$("#divtochangeFont p").css("font-size","16px");
mqsoh
  • 3,160
  • 1
  • 23
  • 26
0

Try something like this, so you won't need to worry about other elements

$("#divtochangeFont").addClass("important").css("font-size","16px");

How to apply !important using .css()?

Community
  • 1
  • 1
bevacqua
  • 45,496
  • 53
  • 165
  • 281