jquery - Why does this javascript code to increase font size work in Firefox but not in Chrome? -


I am using this javascript code so that the font size of the text can be extended to a span so that its parent div fill.

  function maximise_font (the_span, the_div, the_fontsize) {var fontSize = the_fontsize; Var our text = the_span; Var maxHeight = the_div.height (); Var maxWidth = the_div.width (); Var textHeight; Var textwidth; {Make ourText.css ('font-size', font size); TextHeight = ourText.height (); TextWidth = ourText.width (); FontSize = fontSize - 1; } While (TextHight> MaxHit; TextView> MaxWidth & amp; Font Size> 3); }   

It works fine in Firefox, but not in Chrome. In Chrome, the inner loop is run at the same time as in Firefox, but the font size does not change at all. Why is it like this?

Believing our text is a jQuery object, it seems that this is your problem:

  ourText.css ('font-size', fontSize);   

You need to specify the unit type:

  ourText.css ('font-size', font size + "px");   

I'm guessing that Firefox is just making some assumptions for you.

Comments