Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
172
rated 0 times [  175] [ 3]  / answers: 1 / hits: 22337  / 13 Years ago, wed, february 1, 2012, 12:00:00

1) How do I find the row number/index in a HTML table? The generated table doesn't have any id for row.



eg: I have a plain HTML table generated, which has 10 rows,
I am adding rows dynamically to this table.(in between existing rows)



Since I am adding new row, the existing row index will change. Now I need to to find the index of each row before adding the new row.


More From » jquery

 Answers
17

1) How do i find the row number/index in a HTML table? The generated table dosen't have any id for row.




If you mean that you already have a row, and you need its index, don't use jQuery to get it. Table rows maintain their own index via the rowIndex property.



$('table tr').click(function() {

alert( this.rowIndex ); // alert the index number of the clicked row.

});


Demo: http://jsfiddle.net/LsSXy/


[#87693] Tuesday, January 31, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
travion

Total Points: 137
Total Questions: 96
Total Answers: 103

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
travion questions
Mon, Dec 16, 19, 00:00, 5 Years ago
Sat, Oct 19, 19, 00:00, 5 Years ago
Fri, Sep 20, 19, 00:00, 5 Years ago
Wed, Nov 14, 18, 00:00, 6 Years ago
Sun, Oct 28, 18, 00:00, 6 Years ago
;