Based on the different answers received, the only solution using jQuery without implementing our own selector function is a basic selector with ":first" or followed by ".eq(0)" for jQuery.
I wanted to know if their were any kind of max depth option or a function like "get only the first result then return it" but it seems it's not available in jQuery since even :first in the selector does not seem to be faster that a call to .eq(0) Thanks for all the comments.
Original post:
I'm wondering if a function like "closest" is available for the children elements.
Let's say I have an html structure like that:
div.container > [* some elements, I can't use children()] > div.sub1 > div.sub2 > div.sub1 > [other various children elements]
If I want the first div.sub1 I'm doing something like:
$("div.container").find("div.sub1").eq(0)
The problem is that we cannot specify a "max depth" so it will be searched in ALL the children. I see it as a performance issue.
I'm talking about "max depth" because I could list the possibles selectors cases but it would be a long list, about 6-10 items depending on the case.
Anyone has a solution for this?
Thank you