Home » CodeDigest


Highlight HTML Table Row based on the Row Data Using jQuery
Submitted By Satheesh Babu B
On 8/6/2009 9:12:26 AM
Tags: CodeDigest,jQuery  

Highlight HTML Table Row based on the Row Data Using jQuery

At times there will be requirements to highlight a table row based on a data in that row. For example, highlighting a table row which has a specific data in order to differentiate it from other rows.


The below jQuery snippet will highlight the row which has the word "Satheesh" contained in one of the table cell.

     <script src="_scripts/jquery-1.3.2.min.js" type="text/javascript"></script>    
    <script language="javascript">
        $(document).ready(function() {          
            $('#Students td:contains(Satheesh)').parent().addClass('row');

    <form id="form1" runat="server">
    <table id="Students">


Another thing to note in the above code is, it will highlight all the rows that have the string "Satheesh" in any of its TD.

If you want to check the specific TD instead of checking all the TD's in a row,

$('#Students td:nth-child(2):contains(Satheesh)').parent().addClass('row');


The above code will search for the word "Satheesh" only in second TD of every row.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..