开发者

how to find a certain row index in table using jquery

开发者 https://www.devze.com 2023-01-30 00:55 出处:网络
how can i find the index number of a row (tr) with a certain id value in a table with jquery? i mean i want to know for example the row with id=\"2\" is wher开发者_如何学Goe in a table.You can use .in

how can i find the index number of a row (tr) with a certain id value in a table with jquery? i mean i want to know for example the row with id="2" is wher开发者_如何学Goe in a table.


You can use .index() without any parameters to get an element's position amongst siblings, like this:

var i = $("#2").index();

Note though that 2 isn't a valid ID in HTML4, it should be prefixed with something, since IDs can't start with numbers. Also there's the much faster/simpler .rowIndex DOM property way:

var i = document.getElementById("2").rowIndex;

Or, the combination:

var i = $("#2")[0].rowIndex;
0

精彩评论

暂无评论...
验证码 换一张
取 消