$('ul:not(.sub-menu) > li, ul.sub-menu > li:last-child').not(':has(ul.sub-menu)');
.parent() inside multiple selector
-
15-01-2022 - |
Question
I want to select a couple of targets:
- Every direct
li
descendant whose parent is not.sub-menu
(unless it's the last, cf. 2.) - Every last li element of an
ul.sub-menu
- Exclude all
li
's that are parent to aul.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?
Solution
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