I got a jquery script that counts words and adjusts the font size depending on the number of words. The problem is that it counts all attributes with h1 in the parent. I want it to be counted separately for each h1. Initially, the script is marked as h1: first. Here is a script where it considers all h1 in the wofa class:
$(function(){ var $quote = $(".wofa h1"); var $numWords = $quote.text().split(" ").length; if (($numWords >= 1) && ($numWords < 3)) { $quote.css("font-size", "1px"); } else if (($numWords >= 3) && ($numWords < 6)) { $quote.css("font-size", "5px"); } else if (($numWords >= 20) && ($numWords < 30)) { $quote.css("font-size", "10x"); } else if (($numWords >= 30) && ($numWords < 40)) { $quote.css("font-size", "15px"); } else { $quote.css("font-size", "1px"); }
});
user1850380
source share