$('table td:eq(2) a') return the a tag of the third column but only from the first row.
Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is not a bug but it is definitely confusing. What will give you the result you expect is:
While :nth-child and :eq seem very similar the behavior can be quite different as can be seen from the result you expected.
The jQuery documentation on this can be found here.
It states:
In simpler words, eq(2) will select the third element in the while result set while :nth-child(3) will select the 3 child of its parent. And in this case the parent will be its tr.