I've run into a few situations where I need to modify a set of elements by mapping each element to a solitary descendant (or no descendant, if none match the specified filter).
For example (below), in each TR, I would like to find the first TD of class "foo", and then the anchors in this modified set.
However, $('tr td.foo a') gives me all anchors and there's no point in the chain (at least, none that I know of) where I can instruct the query to limit the search to one descendant per ancestor (I'm assuming there's no regularity in the ordering so that :eq(), :nth-child() etc. can't be used on the final set).
Not the end of the world, but prone to two problems:
If we have a large number of elements or deeply nested selectors, this quickly becomes an efficiency issue. We could be searching through 100 TD's per TR when we might only need to look at 1.
In cases where multiple one-to-(zero-or-one) mappings are required for the same query, the code bulks up quite a bit.
A nice feature to have would be the equivalent of an ":nth-found()" pseudoselector, which applies to each individual object's find results before all results are aggregated into a new set. For example,
$('tr td.foo:nth-found(1) a:nth-found(1) b') to return A and E rather than A, B, C, D and E.
:nth-found() is just what I happen to need. More generally, it would be nice to be able to specify that any filter apply pre-aggregation rather than post-aggregation.
I'm submitting this to "Questions" rather than "Ideas" because I have a sneaking suspicion that there is a way of doing this that's more straightforward than chaining .each() .find() .first()'s. Any ideas?
If there isn't an elegant workaround, perhaps a mod could move this to "Ideas". ;)