user1551120
user1551120

Reputation: 627

jQuery Selecting Checkbox In Specific Row

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 ?

Upvotes: 1

Views: 1109

Answers (3)

Julien Royer
Julien Royer

Reputation: 1429

Your selector is wrong. Try this:

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

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

Upvotes: 1

skobaljic
skobaljic

Reputation: 9614

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.

Upvotes: 0

pmandell
pmandell

Reputation: 4328

Check out the use of .eq().

jQuery .eq()

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

Upvotes: 0

Related Questions