Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS [Solved] Tricky :nth-child question Re: [Solved] Tricky :nth-child question

#74757
Chris Coyier
Keymaster

Careful here:

$('li')[3].addClass('second-last');

When you pull an item out of the array like that it becomes a DOM node and jQuery specific functions like addClass will not work on it anymore. You’d have to do:

$('li').eq(3).addClass('second-last');

to have that work. And remember that’s 0-indexed just like arrays =)