Skip to content

Instantly share code, notes, and snippets.

@camerond
Created October 8, 2012 15:45
Show Gist options
  • Save camerond/3853191 to your computer and use it in GitHub Desktop.
Save camerond/3853191 to your computer and use it in GitHub Desktop.
Make a <tr> with a single anchor inside of it clickable
$.fn.clickableTableRows = function() {
return this.each(function() {
var $table = $(this);
var bindEvents = true;
$table.find("tbody tr").each(function() {
var $tr = $(this);
if ($tr.find("a").length != 1 || $tr.find("input:visible").length) {
bindEvents = false;
return;
}
});
if (bindEvents) {
$table.addClass("clickable");
$table.delegate("tbody tr", "click", function() {
$(this).find("a").trigger("click");
});
$table.delegate("tbody a", "click", function() {
window.location.href = $(this).attr("href");
return false;
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment