Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Table Row and Column Highlighting on multiple tables Re: Table Row and Column Highlighting on multiple tables

#132385
Merri
Participant

I did other kind of improvements on this: http://codepen.io/Merri/pen/IDlhq

$(function() {

$(‘table’).on(‘mouseenter mouseleave’, ‘td’, function(e) {
(function(td, type) {
td.parent()[type](‘hover’);
td.closest(‘table’).children(‘colgroup’).eq(td.index())[type](‘hover’);
})(
$(this),
e.type === ‘mouseenter’ ? ‘addClass’ : ‘removeClass’
);
});

});

Removed some code repetition, used mouseenter instead of mouseover and also fixed the bug of not finding the related colgroup elements. CodePen sample also includes code to add new rows so you can see it is indeed dynamic.