Forums

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

Home Forums JavaScript [Solved] Add Class to Parent if Checkbox is Checked Re: [Solved] Add Class to Parent if Checkbox is Checked

#93709
Mottie
Member

This code: $(this).parent().length points to the parent of the link, which is the LI. Try this (demo):

$(this).parent().siblings().length;

Or this would work too, but a bit more messy

$(this).parent().parent().find('li').length;

It uses .parent().parent() instead of .closest('ul,ol') since I’m not sure it works and I’m too lazy to test it.