Reputation: 8606
I have a table like this
<table class="paginated">
<thead>
<tr>
<th scope="col">A</th>
<th scope="col">B</th>
<th scope="col">Error</th>
<th scope="col">D</th>
</tr>
</thead>
<tbody>
<tr>
<td>Error</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>Error</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>Error</td>
<td>4</td>
</tr>
</tbody>
</table>
<script type="text/javascript" src="resources/javascripts/tablePagination.js" /></script>
Actually i want to highlight that row that has Error text in Error column
I am using the following script
$("tbody tr td:contains('Error')").each(function(){
$(this).parent().addClass('highlightedRow');
});
But the problem is if i have Error text even in first column then my row is getting highlighted like
<tr>
<td>Error</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
How can i only check that if the error column of my table has Error text then my row gets highlighted?
Thanks
Upvotes: 0
Views: 162
Reputation: 227260
Just add an extra condition to the selector. :eq(2)
, for the 3rd column.
$("tbody tr td:eq(2):contains('Error')")
Upvotes: 2
Reputation: 298196
You can use :eq()
to select it:
$('tbody tr').has('td:eq(2):contains("Error")').addClass('highlightedRow')
Upvotes: 5