I have several articles, but all of them should correspond to the same space. Characters are limited to 140. What I want to do is change the font size based on the characters in my paragraph. Therefore, if there are fewer characters in the paragraph, I would like the font size to become larger and vice versa.
My code below does not seem to work and was wondering if anyone could help me?
What is happening at the moment, it seems that it takes the last place, because the font size of all paragraphs is 8em :(
I really appreciate any help and thanks in advance!
Here is the code:
$(function(){ var $quote = $(".question p"); var $numWords = $quote.text().split("").length; if (($numWords >= 1) && ($numWords < 20)) { $quote.css("font-size", "2.2em"); } else if (($numWords >= 20) && ($numWords < 60)) { $quote.css("font-size", "1.8em"); } else if (($numWords >= 60) && ($numWords < 100)) { $quote.css("font-size", "1.2em"); } else if (($numWords >= 100) && ($numWords < 140)) { $quote.css("font-size", "0.9em"); } else { $quote.css("font-size", "0.8em"); } });
source share