eozzy
eozzy

Reputation: 68650

jQuery nth element with custom markup

As shown here: http://jsfiddle.net/3sNbV/

$('.box:nth-child(5n)').addClass('edge');

.. the nth element is incorrect if you have any other html elements in there besides the one its looking for, although I've specifically given a classname.

Is there a way to avoid this behaviour without changing the markup?

Thanks

Upvotes: 1

Views: 22

Answers (1)

ced-b
ced-b

Reputation: 4065

Use this instead:

$('.box:nth-of-type(5n)').addClass('edge');

Upvotes: 3

Related Questions