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

前端 未结 5 720
执笔经年
执笔经年 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:42

    Try:

    var index = $("table tr").index(this);
    

    The documentation for index() says:

    Searches every matched element for the object and returns the index of the element, if found, starting with zero. If a jQuery object is passed, only the first element is checked.

    You need to call the index() on a collection of elements, not the parent

    .

    提交回复
    热议问题