I’m trying to highlight the table cell that is in row, col.
var $tr = $('tr:eq(' + row + ')');
$($tr:nth-child(col)).addClass('highlight');
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.
Using
.find(). See demo.Alternatively, if you don’t need a reference to the
$tr, you can do it all via one selector:(Demo)
As for your question
The result of (all) jQuery traversal / selector methods is of type
jQuery. This makes it possible to do advanced chaining. Also, it is on this type that the jQuery methods is defined. This means that you need to perform filtering etc. on the resulting object. Thus, the following is invalid (:is not a JavaScript operator,nth-child()is (probably) not defined as a JavaScript function):But can be rewritten as:
Here we’re applying the selector
:nth-child(1)on thejQueryobject assigned to$tr. This object can hold a reference to any number of DOM elements, even zero!