Monday, September 14, 2015

Table column color changing in using jquery

HTML

<table id="myTable">
<tr><td>Id</td><td>Jack</td><td>Group</td></tr>
<tr><td>1</td><td>Sarah</td><td>1</td></tr>
<tr><td>2</td><td>Teddy</td><td>2</td></tr>
<tr><td>3</td><td>John</td><td>3</td></tr>
<tr><td>4</td><td>Reag</td><td>1</td></tr>
</table>

jQuery



  $(document).ready(function(){
    var currentGroup = "Group";
    $("table tr").each(function() {
     if($(this).find('td:eq(2)').text()==currentGroup){
     
          $("td:eq(2)").css('color','red');
     }
     
    });

});

Result
IdJackGroup
1Sarah1
2Teddy2
3John3
4Reag1


No comments:

Post a Comment