<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> 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?
怪我咯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
伊谢尔伦2017-05-16 13:05:57
Filter numbers greater than 2
$(".number").each(function(){
if($(this).html() > 2){
$(this).css("color","red");
}
});
滿天的星座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';
}
}