I'm exploring how to style a table in such a way that the border can be changed when the mouse hovers over a column.
When the mouse is over a column, I want to highlight that column by changing the border color:
To highlight, I am using the following JavaScript code with the jQuery library:
$('td').hover(function() {
var t = parseInt($(this).index()) + 1;
$('td:nth-child(' + t + ')').addClass('highlighted');
},
function() {
var t = parseInt($(this).index()) + 1;
$('td:nth-child(' + t + ')').removeClass('highlighted');
});
with the following CSS:
.highlighted {
border-top: 2px solid black;
border-right: 2px solid black;
border-left: 2px solid black;
}
You can view how this works in this JSFiddle: http://jsfiddle.net/sCFjj/1/ This is only working when I hover on the left-most column. Otherwise it highlights the right-column (and top) but not the left vertical column. Is there a way of making the left-vertical column appear?
Ideally, I would like the effect to ignore the lowest row, but I am not sure how to exclude a row from the jQuery selection.
I've based my attempt closely on this previous question.