// Mouse over event handler
$('table').on('mouseover', 'td', function() {
// Store the hovered cell's text in a variable
var textToMatch = $(this).text();
// Loop through every `td` element
$('td').each(function() {
// Pull selected `td` element's text
var text = $(this).text();
// Compare this with initial text and add matching class if it matches
if (textToMatch === text)
$(this).parent().addClass('matching');
});
});
// Mouse out event handler
// This simply removes the matching styling
$('table').on('mouseout', 'td', function() {
$('.matching').removeClass('matching');
});
Note that I've modified your CSS slightly to add:
tr:hover, tr.hover, tr.matching {
background: #E5E5E5;
}