Вы можете сделать что-то подобное с помощью добавления / удаления классов.Вы должны указать td/th
, чтобы добавить к ним css
.Я использую removeClass
метод, чтобы уменьшить путаницу с двумя !important
css
свойствами.
$("#customers tr:odd").hover(function() {
$(this).prev().find('th').removeClass('black');
$(this).prev().find('th').addClass('red');
}, function() {
$(this).prev().find('th').removeClass('red');
$(this).prev().find('th').addClass('black');
});
#customers {
width: 100%;
}
#customers td {
border: 1px solid #ddd;
}
#customers tr:hover {
background-color: yellow;
}
#customers th {
text-align: center;
background-color: #4CAF50;
color: white;
}
.red {
background-color: red !important;
}
.black {
background-color: black !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
</head>
<body>
<table id="customers">
<tr>
<th colspan="3"> Words</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr colspan=3>
<th colspan="3"> More Words </th>
</tr>
<tr>
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
</table>
</body>
</html>