Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12511 closed bug (notabug)

$.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/

Change History (2)

comment:1 Changed 7 years ago by scottgonzalez

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".

comment:2 Changed 7 years ago by timmywil

Resolution: notabug
Status: newclosed
Note: See TracTickets for help on using tickets.