Question

I want to select a couple of targets:

  1. Every direct li descendant whose parent is not .sub-menu (unless it's the last, cf. 2.)
  2. Every last li element of an ul.sub-menu
  3. Exclude all li's that are parent to a ul.sub-menu

I was thinking something like this, but that doesn't seem to work: $("ul:not(.sub-menu) > li, ul.sub-menu > li:last, ('ul.sub-menu').parent()")

How would one go about when trying to select an element with non-css selectors inside multiple selectors?

Was it helpful?

Solution

$('ul:not(.sub-menu) > li, ul.sub-menu > li:last-child').not(':has(ul.sub-menu)');

OTHER TIPS

Try this one:

$('ul:not(.sub-menu) > li, ul.sub-menu > li:last-child, li:not(:has(ul.sub-menu))')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top