Add CSS Class to link based on Character Count with jquery

Posted by Wes on Stack Overflow See other posts from Stack Overflow or by Wes
Published on 2010-04-27T02:36:49Z Indexed on 2010/04/27 2:43 UTC
Read the original article Hit count: 249

Filed under:

I have links that load dynamically onto a background to make them look like buttons. Some of the links take up two lines and some of the links take up 1 line. Eithe way they need to be vertically centered.

My plan to to append a class based on the number of characters and then adjust the padding from there.

So if the link's text is 25 characters (including spaces) or less - append class 'small'

if the link's text is greater than 25 characters - append class 'large'

How would I go about doing this with jQuery?

© Stack Overflow or respective owner

Related posts about jQuery