search

Home  >  Q&A  >  body text

javascript - filtering issues; modifying style issues

<p class="namber">2</p>
<p class="namber">3</p>
<p class="namber">3< ;/p>
<p class="namber">4</p>
<p class="namber">8</p>
<p class="namber">1</p>
<p class="namber">4</p>

There is such a set of data; now I want to filter out the data that is greater than 2; and give it a red color; how can I achieve this?

过去多啦不再A梦过去多啦不再A梦2843 days ago380

reply all(4)I'll reply

  • 怪我咯

    怪我咯2017-05-16 13:05:57

    If the index is greater than 2

    p:nth-child(n+2) {
        color: green;   
    }

    If the text is larger than 2, use traversal

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:05:57

    jquery’s each traversal determination

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:05:57

    Filter numbers greater than 2
    $(".number").each(function(){

    if($(this).html() > 2){
        $(this).css("color","red");
    }

    });

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 13:05:57

    Brother, you wrote the number wrong.

    var list = document.getElementsByClassName('number');
      for(var i=0;i<list.length;i++){
          if(list[i].innerHTML > 2) {
              list[i].style.color = 'red';
          }
      }

    reply
    0
  • Cancelreply