Skip to content

.closest() skips origin element #118

@gmac

Description

@gmac

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):

$("a").on("click", function(evt) {
     evt.preventDefault();
     console.log( $(evt.target).closest("a") );
});

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions