问题
I have a Table like this:
<table>
<tr>
<td>
row4545
</td>
</tr>
<tr>
<td>
row22
</td>
</tr>
<tr>
<td>
row6767
</td>
</tr>
</table>
I want to set a background-color on the tr which contains the value row22 in a td. Is it possible to select it somehow with CSS?
PS: I use jQuery.
回答1:
Try
$('tr td').filter(function(){
return $.trim($(this).text()) === "row22";
}).parent().css('background-color', 'blue')
Demo: Fiddle
回答2:
$('td').filter(function(){
return $.trim($(this).text()) === "row22";
}).closest('tr').css('color','red');
Demo ---> http://jsfiddle.net/jJWs2/2/
回答3:
You can write this:
$(document).ready(function() {
$( "td:contains(row22)").css("background-color","red");
});
回答4:
You can try this:
$(function(){
$("td:contains('row22')").filter(function(){
$.trim($(this).text()) == 'row22' ? $(this).parent().attr('style','background:red;') : '';
});
});
回答5:
This should Help..
$('tr td').filter(function() {
return $(this).text() == "row22";
}).parent().css('background-color','red');
回答6:
<table>
<tr style="background:#000;">
<td>
row4545
</td>
</tr>
<tr>
<td>
row22
</td>
</tr>
<tr>
<td>
row6767
</td>
</tr>
</table>
来源:https://stackoverflow.com/questions/17188896/css-selector-select-tr-where-td-contains-special-value