I'm trying to make a bit of code that allows the user to select 1 item from each column in a table by turning it red or something. When another item in that column is clicked on, the red moves to that cell instead. What I want to do is (jQuery code):
$(":nth-child(" + myIndex + ")").removeClass("Selected");
$(this).addClass("Selected");
This works fine, except that I don't know how to get the column index of the cell on which I clicked.
I know I can get round this by looking at the parent's children and seeing which one is me, or by adding classes like "Col1" to each td, but I feel there should be a way to get the index of a child node (surely?). I spent a fair while looking but couldn't find anything useful.  Am I missing something really obvious?
|