Side navigation
#15148 closed feature (plugin)
Opened June 15, 2014 10:45PM UTC
Closed June 16, 2014 04:35PM UTC
Last modified June 21, 2014 02:38PM UTC
findExclude - a descendant traversal feature similar to nextUntil / parentsUntil / prevUntil...
Reported by: | stealthpaladin | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | traversing | Version: | |
Keywords: | findExclude, find, parentsUntil, exclusion | Cc: | |
Blocked by: | Blocking: |
Description
Currently there seems to be no dedicated method to traverse while filtering certain branches.
Usefulness is similar to the *Until methods; I have not named it findUntil as find should not stop descendant traversal except for matching branches.
An example is provided here, in the js section lines 0-22:
Notable use cases:
- Especially good for situations where elements with a given selector exist nested inside elements matching the same selector.
- Can provide new functionality consistent with current traversal methods for descendants where CSS selectors and .not are inadequate.
One example of the problem exists on StackOverflow.
The above problem would be solved with $('table').findExclude('.target','table') which will search within each table individually without crossing into sub-tables. Most helpful when inside $('table').each()
Inspired by my similar, but wordier, problem which is addressed in the JSFiddle.
This is my first go at contributing, so please feel free to direct my attention elsewhere!
Originally I thought to leave this as a plugin but it does seem to fit with the *Until family of logic very closely in traversal methods. There is no particular version in which I think this feature should be introduced.
Attachments (0)
Change History (4)
Changed June 15, 2014 11:06PM UTC by comment:1
Changed June 16, 2014 06:37AM UTC by comment:2
Revised to move .not out of the function by checking !thisObject.is( Mask ) within $( selector ).children().each()
This should save performance by sorting child elements only once
GitHub branch updated.
Changed June 16, 2014 04:35PM UTC by comment:3
resolution: | → plugin |
---|---|
status: | new → closed |
We're trying to keep the core API surface small and light, but this does seem like a good plugin.
Changed June 21, 2014 02:38PM UTC by comment:4
_comment0: | Hi, thanks for the feedback. Completely understandable. \ \ Just wanted to mention, after getting some further code review on stackoverflow, it was found that the function could be reduced considerably. \ \ So much so, while it may fill a small hole for edge cases, it may also not be needed. The same result is achieved by: \ \ $(any).find(Select).not($(any).find(Mask).find(Select)) \ \ In case anyone happens to arrive here via search or have a similar problem. \ → 1403361767277884 |
---|
Hi, thanks for the feedback. Completely understandable.
Just wanted to mention, after getting some further code review on stackoverflow, it was found that the function could be reduced considerably.
So much so, while it may fill a small hole for edge cases, it may also not be needed. The same result is achieved by:
el=$(anything);
el.find(Select).not(el.find(Mask).find(Select));
In case anyone happens to arrive here via search or have a similar problem.
Attempted a draft of including the function into: /src/traversing.js
From lines 125 - 134. Edit can be found here.