3

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 1

7

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;
Sign up to request clarification or add additional context in comments.

1 Comment

thank you Nick.it is exactly what i need and Happy Wedding ! ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.