1

I have a table in which I need to get the input type checkbox element from a specific row. I tried selecting it like so (let's say I am interested in the first row)

$('tr :nth-child(1):checkbox')

yet I get ALL inputs from the table , not just from the row I need . Any thoughts what I'm doing wrong ?

0

3 Answers 3

1

Your selector is wrong. Try this:

$('tr:nth-child(1) :checkbox')

The pseudo-class nth-child must apply to the selector tr.

Sign up to request clarification or add additional context in comments.

Comments

0

Simple:

$('tr').eq(0).find(':checkbox').doSomething();

for example (zero-based).

Your code is wrong because you have space after tr and that means next selector is in child tree below table-row. Pseudo-selectors must be right after element they apply to, without the space, $('input:checkbox') for example.

Comments

0

Check out the use of .eq().

jQuery .eq()

$('tr').eq(0) //selects first tr

Comments

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.