usersam
usersam

Reputation: 1235

jquery how to find nth child from element variable

I am trying to get 4th child from an element children. When i console element.children()

console.log(element.children())

It shows all children in array which is fine.

enter image description here

I want to get only 4th child , marked in red circle. I tried

console.log(element.find(':nth-child(4)'))

but it shows multiple results from subsequent children. Please help how to select nth child. Thanks

Upvotes: 1

Views: 436

Answers (1)

palaѕн
palaѕн

Reputation: 73896

Try using .eq() once like:

console.log( element.children().eq(3) )
  • Using 3 here as .eq() is zero-based index

Upvotes: 2

Related Questions