Here's a fiddle to describe the situation
I have a table which has cells that light up with a border on hover:
table td:hover {
border: 2px solid #3d8b40;
}
When one of them is pressed, I want to make it have a permanent border mentioned above and while it's active (until the next click), I want to disable the lighting on other cells.
The problem seems to have a simple solution to give all cells a class that prevents the border during activation:
.no-border:not(.active):hover {
border: inherit !important;
}
But there is a lot of cells and I'm afraid that toggling so many classes at once may impact the performance.
Then I also tried this approach:
$('td').click(function() {
if ($(this).hasClass('active')) {
$('table td:hover').css('border', 'inherit');
}
else {
$('table td:hover').css('border', '2px solid #3d8b40');
}
}
The problem with it was that the :hover selector only targeted one cell - the one I was pointing at, and I couldn't figure out how to spread this rule to all of them. And that basically means adding an inline style to an HTML element, which is not better than adding a class when considering performance.
How could I solve my problem?
$('table td').attr('style', ':hover {"border": "inherit !important"}')