Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Filter function not working when there is a "%"

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #209012
    amidigital
    Participant

    This works in placing a background image if a number is in this 1 – 100 range. The problem is I want all the numbers to have % so when I do like 57% it no longer works.

    var tds=$("tr td:last-child").filter(function() {
        if($(this).text()>1&&$(this).text()<100){
        return this;
        }
    });
    tds.css({'backgroundImage':'url(http://www.xxx.com/win.png)'});
    
    
    #209145
    Mottie
    Member

    Actually, you’ll need to parse the number if you want to use a comparison. Try this:

    var tds=$("tr td:last-child").filter(function() {
        var val = parseFloat( $(this).text() );
        if( val >1 && val < 100 ){
            return this;
        }
    });
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.