Is it possible to use jQuery to count how many characters are in, for example, an , and if the amount is greater than XX characters, apply a class to
You could do something like this:
// The number of characters
var XX = 100;
$('li').filter(function() {
return $(this).text().length > XX;
}).addClass('someClass');
Why not select your <li>
element into a variable and get its length?
var length = $('li').html().length;
From here, just check if the value on length is greater than the value you're comparing to and use .addClass()
You can get the amount of characters in a string by doing this a.length, where a is a string.
$('a').each(function(){
if($(this).text().length > XX){
$(this).addClass('someClass');
}
});
If you want to target a specific li item (instead of all li elements in your page) you can give it an ID :
<li id="myli">...</li>
Then if you want to execute your code at page load do something like this :
$(document).ready(function() {
var yourElement = $('#myli');
var charLength = yourElement.text().length;
if(charLength > xx){
yourElement.addClass('yourClass');
}
});