Grow your CSS skills. Land your dream job.

Add Class if more than 3 digits

  • # June 23, 2014 at 11:57 am

    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:

    I am having trouble using ‘this’ properly.
    Please help. Thanks!

    # June 23, 2014 at 12:28 pm
    var length = 3;
    
    $('h1').filter(function() {
        return $(this).text().length > length;
    }).addClass('small');
    

    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.

    # June 23, 2014 at 12:31 pm

    Thanks Paulie_D!

    # June 23, 2014 at 12:33 pm

    Wish I could take the credit…I just googled it and found the answer of Stack Overflow.

    # June 23, 2014 at 1:10 pm

    yes you can…you googled better!
    I was still trying traverse the DOM, ur solution is elegant.

    __
    # June 23, 2014 at 3:19 pm

    I was still trying traverse the DOM, ur solution is elegant.

    Well, he is traversing the DOM; he’s just doing it with jQuery.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".