Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#6700 closed bug (fixed)

.closest() returns duplicates of the same element within the matched set.

Reported by: ajpiano Owned by:
Priority: undecided Milestone: 1.4.3
Component: traversing Version: 1.4.2
Keywords: closest unique ancestors Cc:
Blocked by: Blocking:

Description

If, for instance, someone were to do $("#someTable tr").closest("table"), the returned set will include the same ancestor table-element once for each row in the table, which is an undesirable and unexpected result. The set should be run through jQuery.unique, if necessary, to prevent this from happening.

A simple piece of code that illustrates this issue is

$('<div><span/><span/></div>').find('span').closest('div').length === 2

Change History (5)

comment:2 Changed 13 years ago by dmethvin

need: ReviewCommit

comment:3 Changed 13 years ago by dmethvin

See also #6384; should Sizzle remove dups or should jQuery remove them where they can occur?

comment:4 Changed 13 years ago by john

Priority: undecided
Resolution: fixed
Status: newclosed

comment:5 Changed 13 years ago by ajpiano

#7839 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.