Skip to content

Instantly share code, notes, and snippets.

@shakhal
Created April 9, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakhal/fc55a8aad740d9e595f8 to your computer and use it in GitHub Desktop.
Save shakhal/fc55a8aad740d9e595f8 to your computer and use it in GitHub Desktop.
Toggle all checkboxes in column of HTML table by TH header checkbox
$("th input[type='checkbox']").on("click",function(){
var col = $(this).parent().children().index($(this));
var checked = $(this).is(":checked");
$(this).closest("table").find("tr td:nth-child("+col+") input[type=checkbox]").prop("checked", checked);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment