Forums

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

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #173494
    Harun
    Participant

    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!

    #173495
    Paulie_D
    Member
    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.

    #173496
    Harun
    Participant

    Thanks Paulie_D!

    #173497
    Paulie_D
    Member

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

    #173498
    Harun
    Participant

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

    #173504
    __
    Participant

    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)
  • The forum ‘JavaScript’ is closed to new topics and replies.