Reputation: 65
I'm trying to set a class on a div where there's text inside, but I would like to add a class only if there's a character count of 60.
So something like, "if character count = 60 {" and then I'll add the class. Is this possible?
Upvotes: 1
Views: 56
Reputation: 171698
Can use jQuery filter()
:
$(selector).filter(function(){
return $(this).text().length >= 60;
}).addClass('someClass');
filter()
will reduce the elements defined in selector to subset ( or none) that match conditions returned from the callback
Upvotes: 6