Been scouring the net for the ‘best’ way to do table row highlighting.
Seems that the two main alternatives are:
1 Pure CSS: tr:hover
2 Css + Jquery:
$("table").delegate('td','mouseover mouseleave', function(e) {
if (e.type == 'mouseover') {
$(this).parent().addClass("tr-hover");
}
else {
$(this).parent().removeClass("tr-hover");
}
});
I have no idea what is considered best practise these days. As far as I can ascertain, its only IE7 that doesn’t work properly with the Pure CSS option.
Or, are there other alternatives that I should consider?
Use the CSS
:hovermethod. It does also work in IE7+, provided that a DOCTYPE is set. This statement is backed-up by this MSDN article.According to personal tests (and by this source), standards-compliant mode is not activated when:
or when the DOCTYPE is set, and:
http://is also valid, other protocols are invalid.It is activated with all other DOCTYPEs, including XHTML, XML, and unknown ones.
Pros for CSS:
Pros for jQuery:
(this markup is not that critical, so this would not have a big weight. Who is using IE6 by the way?).