Modify ↓
Ticket #7612 (closed bug: invalid)
Abnormal closest() behaviour
| Reported by: | blablagum@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.5 |
| Component: | unfiled | Version: | 1.4.4 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Let's say I have that basic html list :
<ul id="target">
<li>item a</li>
<li>item b
<ul id="source">
<li>sub item a</li>
<li>sub item b</li>
<li>sub item c</li>
</ul>
</li>
<li>item c</li>
</ul>
I want to point to the element <ul id="target"> using the element <ul id="source">.
I do :
$("#source").closest("ul"); // return the element <ul id="source">
It point on itself where it should return the element <UL id="target">
If I use :
$("#source").closest("ul#target"); // return <ul id="target">
It works as expected.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Thanks for taking the time to contribute to the jQuery project by writing a bug report!
The documentation on closest() says:
So this is the expected behavior maybe you intended to use parents() which doesn't consider the current element as potential match. The documentation on closest() includes a list of the differences between these similar methods and even a sample for the exact behavior you experienced