Side navigation
#12511 closed bug (notabug)
Opened September 11, 2012 03:11PM UTC
Closed September 11, 2012 03:19PM UTC
$.closest(selector) also return starting element
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.8.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The documentation says that $closest() is similar to $.parents() but stop at the first parent found.
But $('.item').closest('.item') return itself...
I've tried various versions with jsFiddle.
see this test : http://jsfiddle.net/x6tnS/
The docs are actually quite clear about the behavior:
The description at the top is "Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree."
There's even a table listing out the differences between
.closest()
and.parents()
with the first one being that.closest()
"Begins with the current element".