Is there a better way to create a dynamic zebra styling for table rows while still being able to hide certain elements without losing the styling? In this code snippet, I'm using the CSS :nth-of-type(even)
to style even rows but running into issues when hiding specific rows. How can I achieve this in a more efficient manner?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<style type="text/css">
table tr:nth-of-type(even){background: yellow;}
</style>
<script type="text/javascript">
function hideRow(){
$(".hidden").hide();
}
</script>
</head>
<body>
<center>
<table cellspacing="0" border="1">
<tbody>
<tr class="table-row">
<td>row1</td>
</tr>
<tr class="table-row">
<td>row2</td>
</tr>
<tr class="table-row hidden">
<td>row3</td>
</tr>
<tr class="table-row">
<td>row4</td>
</tr>
<tr class="table-row">
<td>row5</td>
</tr>
</tbody>
</table>
<input type="submit" onclick=" hideRow()" value="submit"/>
</center>
</body>
</html>
How can I dynamically alter the table's style based on certain conditions?
Сurrent result:
Expected result: