Thanks guys, I have tried all the suggestions on here and have tried to adapt them for my grid. I think I'm very close but for some reason alghout each individual selector/traversal function seems to work in isolation, none of it seems to work when I put it all together. Can anybody spot any problems with my code ?
$(".Grid thead tr th input:checkbox").click( function() { var MyRow = $(this).parent().parent(); var MyCell = $(this).parent(); var index = MyRow.children("th").index(MyCell); alert(index); } ); <div class="Grid"> <div class="Header"></div> <table> <thead> <tr> <th class="CheckBox"><input type="checkbox" class="CheckBoxMaster" /></th> <th class="Heading">Country</th> <th class="Heading">Country Code</th> <th class="CheckBox"><input type="checkbox" class="CheckBoxMaster" /></th> <th class="Heading">Currency</th> <th class="Heading">VAT Applicable</th> </tr> </thead> <tbody> <tr> <td class="CheckBox"><input type="checkbox" class="CheckBox" /></td> <td class="Text">England</td> <td class="Text">ENG</td> <td class="CheckBox"><input type="checkbox" class="CheckBox" /></td> <td class="Text">GBP</td> <td class="Text">YES</td> </tr> </tbody> </table> <div class="Footer"></div> </div> I'm using $(this).parent().parent() because .parents() presumably wouldn't work if I wanted to nest Grids inside each other. I also realise I could do this in 1-2 lines but I'm trying to keep it readable. Thanks, Jon On Nov 26, 7:09 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote: > Hi Jon, > > Here you go: > > $(document).ready(function() { > $('.Grid th').each(function(column) { > column ++; > $('input:checkbox', this).click(function() { > $('.Grid tbody tr td:nth-child(' + column + ') > input:checkbox').attr({checked: $(this).is(':checked') ? 'checked' : > ''}); > }); > }); > > }); > > :-) > > --Karl > _________________ > Karl Swedbergwww.englishrules.comwww.learningjquery.com > > On Nov 25, 2007, at 5:15 PM, jonhobbs 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.