Changing CSS based on the value

前端 未结 4 1428
一整个雨季
一整个雨季 2021-01-22 10:58

I have been asked to implement a small validation on values and if the values are greater or less than 0 i need to change or add/remove the css for the td and i tag

My t

4条回答
  •  抹茶落季
    2021-01-22 11:29

    Here .slice will remove the % sign in this code and the rest of the code will compare the value and assign or remove class

    var sdlyvar = $('#sdlyvar').text();   
    
    if (sdlyvar.slice(0,-1) < 0){
        $('#sdlyvar').removeClass("fa-level-up");
        $('#sdlyvar').addClass("fa-level-down");
    } else {
        $('#sdlyvar').removeClass("fa-level-down");
        $('#sdlyvar').addClass("fa-level-up");
    }
    

提交回复
热议问题