I have following problem need to change style of which is in table cell using jQuery. The change is dependable on value in other cell. I have following table:
<table id="table">
<tr>
<td>
<a href="www.google.pl">YYYYYYYYY</a></td>
<td>HHHHHHH<td>
</tr>
<tr>
<td>Jedi Armor1</td>
<td>HHHHHHH</td>
</tr>
<tr>
<td>Jedi Armor2</td>
<td>HHHHHHH</td>
</tr>
</table>
jQuery method:
$(document).ready(function() {
$('#table tr td').each(function(){
var textValue = $(this).text();
if(textValue == 'HHHHHHH'){
// add css class or any manipulation to your dom.
$(this).parent().css('color','red');
$(this).parent().children('td a').css('color','red');
};
});
// koniec funkcji hover
});
The problem is how to change style??
答案 0 :(得分:0)
如果您将children
更改为find
,则您的代码将有效。
请参阅此fiddle了解演示
答案 1 :(得分:0)
$(this).parent().children('td a')
看不到2级
变化:
$(this).parent().find('a');
到
$(this).parent().addClass('has_H');
但最简单的方法是只在行中添加一个类并使用css调整整行的样式。切换类通常比撤消内联css
更容易tr.has_H, tr.has_H a{
color:red;
}
CSS
div