How to find the index of a row in a table using jquery

前端 未结 5 714
执笔经年
执笔经年 2020-12-01 18:28

I\'m trying to find the index of a row in a table. I\'m trying to use the following code, but I seem to get an index of -1.

$(document).ready(function()
{
           


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 18:51

    Have you tried:

    $("tr").index(this)
    

    The documentation shows just passing this and that the preceding selection should be where the node is found. If you need to find it in a specific table (and there are multiple), you may need to provide some context:

    // haven't tested this
    $("tr", $(this).closest("table")).index(this) 
    

提交回复
热议问题