Frage

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?

War es hilfreich?

Lösung

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

Andere Tipps

Try this one:

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top