Given this sample markup (assuming a random number of elements between .outer
and .inner
:
-
If assume correctly you want to select all .inner
that is beneath an .outer
, except if there is an .outer
inbetween, perhaps following will work (untested):
$('.outer:not(.inner):has(:not(.outer) .inner:not(.outer), > .inner:not(.outer))');
updated after test on OP example HTML at http://jsfiddle.net/cEwBT/1/