Created
October 8, 2012 15:45
-
-
Save camerond/3853191 to your computer and use it in GitHub Desktop.
Make a <tr> with a single anchor inside of it clickable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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