jQuery plugin for selecting ancestors
<div id='d1' class='a b'><div class='x'></div></div>
<div id='d2' class='a c'><div class='x'></div></div>
<div id='d3' class='a b'><div class='y'></div></div>
<div id='d4' class='a b'><div class='x'></div></div>
$('body').ancestors('.a > .x < .b')
returns the DIVs #d1
and #d4
as jQuery element.
Network for professionals Soshace