views:

293

answers:

2

i have a table with thousands of rows. there are no ids and so on.

within the tds of the rows i have a link calling a fucntion and passing "this" to get the link object.

using jquery it is easy to get the the closest tr and table (and so the tables.rows.length)

  1. i want to know as easy in wich row i'am?! ok i could do a loop but does exist any easier possibility?!
#

another table with rows the rows have mixing className in no structured order tr1 tr2, tr4 maybe clsA, tr3 clsB and between them are non "class-named" trs or some called separator

  1. i want to know which row comes first clsA or clsB -> remember it is not the first sibbling etc ther can be empty trs or separator

-> i want to avoid loops, thats why i ask for some jquery tricks?!

+1  A: 

If you have an id on the table you can use this:

$("#TableId td").click(function()
{   
  var index = $("#TableId tr").index(this.parent("tr"));
});

Read more about the index method at http://docs.jquery.com/Core/index

bang
+1 thx for reply, i'll try this
+2  A: 

You don't need to use jQuery to get row's index. There's DOM property 'rowIndex' (which is the fastest way to get row index IMO). See more here http://www.w3schools.com/htmldom/prop_tablerow_rowindex.asp

$("#TableId td").click(function()
{   
  var index = $(this).parent("tr")[0].rowIndex;
  alert(index);
});

Sample here: http://jsbin.com/oroje

algiecas