Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can a html table highlight columns by changing the border on hover?
    primarykey
    data
    text
    <p>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.</p> <p><img src="https://i.stack.imgur.com/TCDXZ.png" alt="enter image description here"></p> <p>When the mouse is over a column, I want to highlight that column by changing the border color:</p> <p><img src="https://i.stack.imgur.com/EVBW9.png" alt="enter image description here"></p> <p>To highlight, I am using the following JavaScript code with the jQuery library:</p> <pre><code>$('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'); }); </code></pre> <p>with the following CSS:</p> <pre><code>.highlighted { border-top: 2px solid black; border-right: 2px solid black; border-left: 2px solid black; } </code></pre> <p>You can view how this works in this JSFiddle: <a href="http://jsfiddle.net/sCFjj/1/" rel="nofollow noreferrer">http://jsfiddle.net/sCFjj/1/</a> 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?</p> <p>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.</p> <p>I've based my attempt closely on this previous <a href="https://stackoverflow.com/a/11828637/258755">question</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload