I have a div that I want to detect the length of; if it's 10 or more, I want it to display in a smaller font-size.
$(window).load(function() {
function adjustFontSize() {
var theTitleLength = $('.article-title-on-list').text.length;
if (theTitleLength >= 10) {
$('.article-title-on-list').css('font-size', '1.5rem');
} else {
$('.article-title-on-list').css('font-size', '2rem');
};
};
adjustFontSize();
};
<div class="article-title-on-list">12345678901234567890</div>
The function fails silently.
text
is method and not property. use .text()
instead of .text
var theTitleLength = $('.article-title-on-list').text().length;