fabjoa
fabjoa

Reputation: 1615

How to retrieve a element by class name by its position

How do you translate the following into jQuery?

document.getElementsByClassName('x')[5]

$('.x')[5] does not seem to work. i could go with a

$('.x').each(){function(i){ if(i==5) return $(this) })

but there must be an easier inline way.

Upvotes: 1

Views: 68

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

You could use the :eq() selector:

$('.x:eq(5)');

Upvotes: 3

Related Questions