I am facing a situation where I have an HTML table with numerous cells, some of which are assigned classes like hov1
, hov2
, ..., hov42
, ..., all the way up to hov920
.
This is a compact table where the darker green cells (hov1
) change when hovered over while the light green ones (hov2
) remain unaffected (this behavior is executed via JavaScript and performs well unless the table grows in size).
https://i.sstatic.net/gJzz8.png
...
<td class="hov0" style="background-color: rgba(0, 200, 0, 0.1);">AA</td>
<td">00</td>
<td class="hov2" style="background-color: rgba(0, 200, 0, 0.1);">BB</td>
<td class="hov2" style="background-color: rgba(0, 200, 0, 0.1);">CC</td>
...
I am aware that I can use CSS wildcards to apply a hover effect to all classes containing hov
. However, I only want specific classes to be affected by hovering and not all hov
-classes.
Is there a way to further filter out numbers so that only hov1
or hov42
trigger the hover effect in CSS? As far as I know, there are only two potential solutions:
CSS (potentially not ideal):
hov1:hover, hov2:hover, hov3:hover ... hov99:hover {
background: rgba(0, 200, 0, 0.5);
}
jQuery (highly resource-intensive, crashes my browser):
$(this).addClass("hov" + x);
$(this).hover(function(e) {
$(".hov" + x).css("background-color",e.type === "mouseenter"?"rgba(0, 200, 0, 0.5)":"rgba(0, 200, 0, 0.1)")
})
Are there any other alternatives to address this complex issue?