DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Linked Table Jquery Plugin

05.24.2010
| 2542 views |
  • submit to reddit
        This is a simple jquery plugin for adding a click handler to a table row. The click handler searches the descendants of the TR for an anchor with the class "row-link". When found the window.location is set to the value of the href attribute, sending the user to that page.

example: $("table-selector").linkRows();

$.fn.linkRows = function() {
  $(this).each(function() {
    $("a.row-link", "tr").each(function() {
      var $a = $(this);
      $(this).closest("tr")
        .click(function() {
        window.location = $a.attr("href");
      });
    });
  });
  return this;
};