Assuming you a single checkbox in each th cell... var thboxes = $('.Grid thead th input:checkbox'); thboxes.click(function(){ var colNum = thboxes.index(this) + 1; // then your stuff... $(".Grid tbody tr td:nth-child(" + colNum + ")input:checkbox").each(function() { this.checked = true; }); });
If you don't have a single checkbox in each and every th cell then you need to stop the thboxes selector at th, add a find() before the click(), and change the index()... var thboxes = $('.Grid thead th'); $('input:checkbox', thboxes).click(function(){ var colNum = thboxes.index( $(this).parents('th')[0] ) + 1; .... .... }); On Nov 25, 10:15 pm, jonhobbs <[EMAIL PROTECTED]> wrote: > Hi, > > I hope somebody can help me. I'm trying to write a function which will > tick every checkbox in a column when you tick the checkbox in the > header. > > The plan is to attach an evetn to every checkbox in the header which > when you check it will find the column bumber of the cell it is in and > plug that number into the following code where the x is... > > $(".Grid tbody tr td:nth-child(x) > [EMAIL PROTECTED]'checkbox']").each(function() { > this.checked = true; > > }); > > I can figure out how to get the parent element of the checkbox (which > will be a TD), just don't know how to find out that cells position in > the table row. > > Any help would be appreciated.