JQuery: If a custom class contains a number greater than 'x' add CSS code

前端 未结 2 1899
北恋
北恋 2021-01-26 17:51

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 b

相关标签:
2条回答
  • 2021-01-26 17:58

    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'});
    
    0 讨论(0)
  • 2021-01-26 18:23
    $(function(){
        $('.subTotalPrice').each(function(){
            if(parseInt($(this).text, 10) > 55){
                $(this).css({'color':'red', 'text-decoration':'underline'});
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题