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,779
  • 12
  • 49
  • 76

5 Answers5

1
$("#divtochangeFont, #divtochangeFont *").css("font-size", "16px");
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
1
$("#divtochangeFont * ").css({"font-size": "16px","color": "orange"});

you only need to take all children of your div

Aram Mkrtchyan
  • 2,690
  • 4
  • 31
  • 47
0

you could do something like:

$("#divtochangeFont").css("font-size","16px");
$("#divtochangeFont").children().each(function () {
  $(this).css("font-size","16px");
});
tmaximini
  • 8,403
  • 6
  • 47
  • 69
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,180
  • 2
  • 24
  • 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
  • 47,502
  • 56
  • 171
  • 285