I've got this little snippet that I use for row highlighting on an XSLT page that has to use an onclick event to postback some data, but because the row isn't a link I have to make sure there's a hand cursor as well as the row being highlighted so the users understand it's clickable and what row they're on.
<script type="text/javascript">
$(document).ready(function() {
$('#stocks tr:not(.exclude)').css('cursor', 'hand');
$('#stocks tr:not(.exclude)').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
});
</script>
The tables are large, typically up to 5000 rows. When there's a large amount of rows the row highlighting used by this jQuery script goes quite slow. I wrote the tr:not(.exclude)
selector, but I'm thinking perhaps that's what's causing it to go slow? Any ideas on how to speed this up?
EDIT: I see many answers are very good, however they do not address the fact of there being over 5,000 rows at least.
EDIT EDIT: You MUST ensure that IE7 at least has the following doctype set in order for tr:hover to work. Mine still goes slow, however this must be down to something else.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">