- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Add Class if more than 3 digits
I am a JS rookie. I am trying to make the the text inside the circle smaller for when the number is more than 3 digits.
Here is my pen:
http://codepen.io/hrazith/pen/Jljzs
I am having trouble using ‘this’ properly.
Please help. Thanks!
var length = 3;
$('h1').filter(function() {
return $(this).text().length > length;
}).addClass('small');
http://codepen.io/Paulie-D/pen/LrhvB
It’s not based on the actual value…just the number of characters…if over 999 then there must be 4 characters and there you are.
Thanks Paulie_D!
Wish I could take the credit…I just googled it and found the answer of Stack Overflow.
yes you can…you googled better!
I was still trying traverse the DOM, ur solution is elegant.
I was still trying traverse the DOM, ur solution is elegant.
Well, he is traversing the DOM; he’s just doing it with jQuery.