Skip to content Skip to sidebar Skip to footer

Jquery: If A Custom Class Contains A Number Greater Than 'x' Add Css Code

I would like to add css to a assigned span class if it contains a number higher than 55, also this must on a page load and not a button trigger. Thanks any help would be great. E

Solution 1:

Here's a good way of doing that using jQuery's filter():

$('.subTotalPrice').filter(function(index){
    return parseInt(this.innerHTML) > 55;
}).css({'color':'red', 'text-decoration':'underline'});

Solution 2:

$(function(){
    $('.subTotalPrice').each(function(){
        if(parseInt($(this).text, 10) > 55){
            $(this).css({'color':'red', 'text-decoration':'underline'});
        }
    });
});

Post a Comment for "Jquery: If A Custom Class Contains A Number Greater Than 'x' Add Css Code"