Reputation: 5887
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?
Upvotes: 1
Views: 258
Reputation: 348972
Use the CSS :hover
method. It does also work in IE7+, provided that a DOCTYPE is set. This statement is backed-up by this MSDN article.
... improve CSS2.1 compliance. All this work (with the exception of transparent PNGs) has been done under the <!DOCTYPE> switch only, since all changes required behavioral updates to be more in line what the CSS spec specifies.
. . .
We also extended our existing implementations to comply with W3C specifications:
- Enable :hover on all elements not just on
<a>
According to personal tests (and by this source), standards-compliant mode is not activated when:
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:
Upvotes: 4