I have a table full of tabular data. I need to find the index of a column(cell) in the table.
For example:
<table>
<tr>
<td>Column1</td>
<td>Column2</td>
<td>Column3</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>foobar</td>
</tr>
</table>
function TestIndexOf(someTD)
{
$(someTD) // what's my column index?
}
$('td').prevAll().lengthwill give you the 0-based index of a cellAlternatively using
index()(can pass a DOM element or a jQuery object in. If jQuery object, only the first object in the wrapped set is used)If I recall correctly,
index()will be easier to use in jQuery 1.4 and will allow you to simply call index() on the element wrapped in a jQuery object to get the index, like soSo for your function