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 where in a table.
1 Answer
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;
1 Comment
hd.
thank you Nick.it is exactly what i need and Happy Wedding ! ;)