[英]How to change anchor <a> style when it's in table cell using jquery
I have following problem need to change style of which is in table cell using jQuery. 我有以下问题需要更改使用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: jQuery方法:
$(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?? 问题是如何改变风格?
children()
can't look 2 levels down children()
不能向下看2级
Change: 更改:
$(this).parent().children('td a')
to 至
$(this).parent().find('a');
But simplest would be to just add a class to the row and use css to adjust the style for the whole row. 但最简单的方法是将一个类添加到行中,然后使用css调整整个行的样式。 It's generally easier to switch classes than undo inline css
与撤消内联CSS相比,切换类通常更容易
$(this).parent().addClass('has_H');
CSS CSS
tr.has_H, tr.has_H a{
color:red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.