开发者

how to find a certain row index in table using jquery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜