Home › Forums › CSS › Table Row and Column Highlighting on multiple tables › Re: Table Row and Column Highlighting on multiple tables
April 19, 2013 at 12:02 am
#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.