Forums

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

Home Forums JavaScript [Solved] Table Row Hover with Rowspan Reply To: Table Row Hover with Rowspan

#149729
rvencu
Participant

Hi, I have a case with very complicated table (generated using the wordpress Tablepress plugin) which has multiple rowspans and colspans on various parts of the table. The script above is not good enough so I came with an improved one that works well on my table here http://ivory.dentfix.ro/lista-preturi/

Here is the code:
var el;
var maxCol;
jQuery(function() {
jQuery("td").hover(function() {
el = jQuery(this);
maxCol = colCnt(el.closest('table').find('tr:first'));
if (colCnt(el.parent()) < maxCol ) {
markUp(el.parent().prevAll('tr:has(td[rowspan]):first'),maxCol-colCnt(el.parent()));
}
}, function() {
el.parent().prevAll('tr:has(td[rowspan])').find('td[rowspan]').removeClass("hover");
});
});
function colCnt(elem) {
var colCount = 0;
jQuery (elem.children()).each(function () {
if ($(this).attr('colspan')) {
colCount += +$(this).attr('colspan');
} else {
colCount++;
}
});
return colCount;
};
function markUp (elem,n) {
maxCol = colCnt(elem.closest('table').find('tr:first'));
elem.find('td[rowspan]').slice(0,n).addClass("hover");
if (colCnt(elem)<maxCol) {
markUp (elem.prevAll('tr:has(td[rowspan]):first'),maxCol-colCnt(elem));
}
}