CSS选择器:选择TR,其中TD包含特殊值
我有一个像这样的表:
row4545 row22 row6767
我想在tr上设置背景颜色,其中包含td中的值row22。 有可能用CSS以某种方式选择它吗?
PS:我使用jQuery。
尝试
$('tr td').filter(function(){ return $.trim($(this).text()) === "row22"; }).parent().css('background-color', 'blue')
演示: 小提琴
$('td').filter(function(){ return $.trim($(this).text()) === "row22"; }).closest('tr').css('color','red');
演示--->
http://jsfiddle.net/jJWs2/2/
你可以这样写:
$(document).ready(function() { $( "td:contains(row22)").css("background-color","red"); });
你可以试试这个:
$(function(){ $("td:contains('row22')").filter(function(){ $.trim($(this).text()) == 'row22' ? $(this).parent().attr('style','background:red;') : ''; }); });
这应该帮助..
$('tr td').filter(function() { return $(this).text() == "row22"; }).parent().css('background-color','red');
row4545 row22 row6767