How Can I Determine if a List Item Contains a Child List?
I have an unordered list with many list items several levels deep, some of which contain nested unordered lists. How can I determine which individual list items contain nested lists and attach click events to only those list items? For example:
- <ul>
- <li>level 1
- <ul>
- <li>level 1-1</li>
- <li>level 1-2
- <ul>
- <li>level 1-2-1</li>
- <li>level 1-2-2</li>
- <li>level 1-2-3</li>
- <li>level 1-2-4</li>
- <li>level 1-2-5</li>
- </ul>
- </li>
- <li>level 1-3</li>
- </ul>
- </li>
- </ul>
Level 1 and Level 1-2 should have the click event bound to them while all the other list items don't have anything bound to them.
I assumed that I would loop over all the list items using each() and :has or .children(), but I couldn't figure out how to test if the list item I was iterating on contain a sublist. Any assistance is appreciated.