我正在尝试使用以下代码将不同的样式应用于某个类下方的每个第一表行:
$(".my-class tr:first td").css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});
问题是它只将它应用于它在该类下面找到的第一个表。
我在这里想念什么?
我正在尝试使用以下代码将不同的样式应用于某个类下方的每个第一表行:
$(".my-class tr:first td").css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});
问题是它只将它应用于它在该类下面找到的第一个表。
我在这里想念什么?
Try the following :
$(".my-class").find("tr:first td").css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});
Your previous code was only finding the first row and td, this will find every element with .my-class
and find the first tr/td element of the found elements.
您也可以尝试精确
$(".my-class").find("tr td:eq(0)").css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});
改变
$(".my-class tr:first td")
至
$("table tr:first").has('.my-class').find('td')
尝试这样的事情
$(".my-class tr:first td").each(function(){
$(this).css({"color":"#0064CC","font-size":"15px","border-bottom-style":"none"});
})