Filter by descendent

Filter by descendent


I'm trying to solve the follow selector problem: Assuming two
container elements that both have arbitrary descendents. Given a
jQuery object containing these containers and one descendent of any of
these, whats the most effecient way to find the correct parent
element? Neither parents() nor closest() helps, as there is no
sufficient simple selector available.
In other words, I want to filter a selection by a descendent.
My naiive implementation goes through all descendents, which isn't
really acceptable: http://jsbin.com/uhama/edit
Ideas?
Jörn