Opened 12 years ago
Closed 12 years ago
#7612 closed bug (invalid)
Abnormal closest() behaviour
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | 1.5 |
Component: | unfiled | Version: | 1.4.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
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.
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 onclosest()
includes a list of the differences between these similar methods and even a sample for the exact behavior you experienced