The nth-of-type pseudo-class for CSS represents the same elements that would be matched by :nth-child(|An+B| of S), where S is a type selector and namespace prefix matching the element in question.
selector:nth-of-type(An+B)
{
property: value;
}
<!doctype html>
<html>
<head>
<style>
table, td
{
border-style: solid;
}
tr:nth-of-type(even)
{
background-color: yellow;
}
</style>
</head>
<body>
<table>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
</table>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
table, td
{
border-style: solid;
}
tr:nth-of-type(odd)
{
background-color: yellow;
}
</style>
</head>
<body>
<table>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
</table>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
table, td
{
border-style: solid;
}
tr:nth-of-type(2n+1)
{
background-color: var(--myvar);
}
</style>
</head>
<body>
<button>initial</button>
<button value="yellow">value</button><br>
<table>
<tr>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
</tr>
<tr>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
</tr>
<tr>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
</tr>
<tr>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
<td>An+B</td>
</tr>
</table>
<script>
function myfunction(myparameter)
{
const mytarget = myparameter.target;
const myproperty = mytarget.value || mytarget.innerHTML;
document.querySelector(":root").style.setProperty("--myvar", myproperty);
}
for(const mybutton of document.querySelectorAll("button"))
{
mybutton.addEventListener("mouseover", myfunction);
}
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
table, td
{
border-style: solid;
}
tr:nth-of-type(even)
{
background-color: var(--myvar);
}
</style>
</head>
<body>
<button>initial</button>
<button value="yellow">value</button><br>
<table>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
<tr>
<td>even</td>
<td>even</td>
<td>even</td>
<td>even</td>
</tr>
</table>
<script>
function myfunction(myparameter)
{
const mytarget = myparameter.target;
const myproperty = mytarget.value || mytarget.innerHTML;
document.querySelector(":root").style.setProperty("--myvar", myproperty);
}
for(const mybutton of document.querySelectorAll("button"))
{
mybutton.addEventListener("mouseover", myfunction);
}
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
table, td
{
border-style: solid;
}
tr:nth-of-type(odd)
{
background-color: var(--myvar);
}
</style>
</head>
<body>
<button>initial</button>
<button value="yellow">value</button><br>
<table>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
<tr>
<td>odd</td>
<td>odd</td>
<td>odd</td>
<td>odd</td>
</tr>
</table>
<script>
function myfunction(myparameter)
{
const mytarget = myparameter.target;
const myproperty = mytarget.value || mytarget.innerHTML;
document.querySelector(":root").style.setProperty("--myvar", myproperty);
}
for(const mybutton of document.querySelectorAll("button"))
{
mybutton.addEventListener("mouseover", myfunction);
}
</script>
</body>
</html>