-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.closest() skips origin element #118
Comments
if this is how jQuery does it — it seems wrong. i don't understand why the same element would be considered the closest. i suppose this is based on the old saying "nobody knows yourself better than you" |
the current implementation is here: i suppose we can change the src to look like this var collection = $(selector), j, k, p, r = []
for (j = 0, k = this.length; j < k; j++) {
p = this[j]
while (p) {
if (~indexOf(collection, p)) {
r.push(p)
if (closest) break;
}
p = p.parentNode
}
} this way it gets seeded with the node itself as opposed to starting it off with the |
Having to I think the problem with the jQuery implementation is purely naming, closest doesn't naturally indicate self-included. But, it's pretty much a must for when you're listening to a DOM event on an element that has child elements so the target may either be the element itself or one of the child elements, hence |
actually, that would be a pretty great the only problem then is that this library only ends up working for people who use Ender and would no longer work as a stand-alone. |
would it need to be a dependency? it could just be added to jeesh if we consider traversal functionality core (which I guess it is!) |
I agree @ded that the naming of |
let's push for a |
First off – thanks, and great work on the Ender suite. This is a slick jQuery alternative.
I have noticed something I would consider an issue with Bonzo's implementation of the
.closest()
command within the Ender bridge. It appears that calling.closest()
does not take the origin element into account as a potential selector target; it only appears to climb the tree from the origin. Take the following example...HTML:
<a href="to.html">Click <b>Me</b></a>
JS (using Qwery, Bonzo & Bean):
In the above example, clicking on the "Click" portion of the anchor finds nothing, while clicking on the "Me" portion of the anchor successfully finds the parent anchor. This differs from the jQuery implementation, which would find the anchor in both cases. I find the jQuery implementation more intuitive, which includes the origin element as a potential candidate in the closest selector search. If I wanted to omit the origin and just search up the tree, I'd use
.parents()
.The text was updated successfully, but these errors were encountered: