please help me with a simple problem in jQuery. I have a load of list items on a page and I need to compare the length of the strings within them. If they are greater than 100 characters then I need to add a class to the 'li' otherwise nothing happens. My code so far:
<ul id="mylist">
<li>This is a string with more than 100 characters in it. This is a string with more than 100 characters in it.</li>
<li>This is a string with less than 100</li>
</ul>
var len = $("#mylist li").text().length;
$( "#mylist li" ).each(function() {
if (len > 100) {
$(this).addClass("test");
}
});