jQuery - Table Row Highlighting

The following example shows how to use jQuery and simple CSS to create a table with highlightable and clickable rows (see working example here):

<style type="text/css">
cursor: pointer;

<table id="example" border='1'>
<td>First Name</td>
<td>Last Name</td>
<tr onclick="alert('John Smith')">
<tr onclick="alert('Jane Doe')">
<tr onclick="alert('Bob Squarepants')">

<script id="vups-script" type="text/javascript">
$("#example tbody td").hover(function() {
}, function() {


  1. any idea how to make rows highlight-able when using the plugin tablesorter by Christian Bach?

  2. I haven't tried it, but inspecting the tablesorter HTML in Firebug it looks like the two methods should work together. That is, say you have a table with id #myTable, you would first attach the tablesorter and then run the code I supplied above to make the rows highlightable and clickable. It should look something like this:

    $("#myTable tbody td").hover(function() { $(this).parents('tr').addClass('highlight');
    }, function() { $(this).parents('tr').removeClass('highlight');

  3. Jay, see the following example for using this with tablesorter: http://dl.dropbox.com/u/642364/blogger/scripts/jq-highlight-ts.html

    The two changes I had to make was make the .highlight css rules !important, and tweak the code to add/remove the hover class as $(this).parents('tr').find('td') so that is adds the .highlight class directly on the cells rather than rows.

    There's probably easier pays to do this, like making the css rule '.highlight td' or using the jQuery .siblings method, etc.

  4. Thank you very much.


Post a Comment

Popular posts from this blog

Wkhtmltopdf font and sizing issues

Import Google Contacts to Nokia PC Suite

Can't delete last blank page from Word