[edit] I reformulated the question and deleted the example, as it confuses you. Sorry for the trouble.
I need to match the first child that matches the selector.
If several elements match this selector, but they are separated by trees (i.e. if one of them is not the parent of the other), I want to select both of them.
The exact structure of the DOM is unknown, so I cannot use functions like .children( ) or the selector > (because they expect the user to be sure of the actual structure of the DOM).
What I really need is similar to the .closest( ) function, but for matching children instead of parents and possibly multiple children at once.
source share