I am wondering how I can loop through a certain column in a table using javascript or jquery.
Also is it possible to skip the first element in the column too.
I have a table of values and I am dynamically adding rows to the table.
So I have a table like
-------------
| A | d | G |
-------------
| D | e | H |
-------------
| c | f | I |
-------------
I have 3 text boxes and a button. Each text box will contain the data that will go into a cell in a new row. When the button is clicked, before adding rows, I want to check if the information in the text box is already added to the column that the text would normally go into.
So for example, if the textboxes contained (O,K,I) respectfully, I would want the code to check the first column for the presence of O, the second column for the presence of K and the third column to check for the presence of I. The code would find a match for I and then alert something.
Each table cell has a bit of text in it.
Update: Use
:nth-child(columnIndex)in the selector. Note that in this casecolumnIndexis not zero based. i.e. if you want the 2nd column, use 2, not 1.Demo: http://jsfiddle.net/pMWAw/
Note: As David Thomas pointed out, using
eq()will filter out just the first matched TD.