Nik So
Nik So

Reputation: 16811

question about finding a more efficient jquery css selector

I have a wrapper div containing 10 thumbnail divs each of which contains 10 img tags, I want an array of the first img tag's of each of these 10 thumbnail divs. Currently I am doing

$('#wrapper').find('.thumbnail').find('img:first') //--> [<img>, <img>, ... , <img>] 10 img tags total

Is there a shorter way to do this?

Thanks!

Upvotes: 0

Views: 57

Answers (2)

CarlosZ
CarlosZ

Reputation: 8669

Do it like this $('#wrapper .thumbnail img:first-child')

Upvotes: 1

mattsven
mattsven

Reputation: 23273

$('#wrapper .thumbnail > img:first-child')

Upvotes: 2

Related Questions