javascript - Apply CSS if text exceeds a certain length -


is there way apply css element if text within element exceeds length. instance <p class="foo">123456789</p>.

then, when text within element exceeds x characters new class applied

<p class="foo text-exceeds-x-chars">12345678910101010101</p> 

i'd suggest using addclass callback function:

$('p.foo').addclass(function() {     return $.trim(this.textcontent).length > 10            ? 'text-exceeds-x-chars'            : null; }); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -