tags:

views:

17

answers:

1

How do I write jQuery selector to test if li has ul that has at least one li that is not .disabled (may be other classes or without class at all).

Yes sounds complex but it's simple - I need to know if there're uls that do not have "disabled" class on inner lis.

Something like

$("li").filter("*:has(ul:has(li:not(.disabled)))")
+1  A: 

You can shorten it a bit, like this:

$("li").filter(":has(ul li:not(.disabled))")

You can try it here. Since the <li> is a child of <ul> you can just refer to it that way, no need for the extra :has() selector confusing Sizzle (multiple :not() in a chain do this as well).

Unless there's the possibility of a <ol> you could remote the ul part as well, just having:

$("li").filter(":has(li:not(.disabled))")
Nick Craver
I made "not(.disabled)" out of my head, didn't think that it was likely to be a valid jQuery selector ;-) Which shows that jQuery selectors syntax is very intuitive. Thanks also for the Fiddle tool link, very useful.
queen3