Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10449 closed enhancement (fixed)

Function $("#id").closest(".class") returns element $("#id") itself if it has .class

Reported by: San4es Owned by: kswedberg
Priority: low Milestone: 1.7
Component: traversing Version: 1.7b1
Keywords: Cc:
Blocked by: Blocking:


Tests were performed on following example with all popular browsers and all versions of jQuery:

<ul class="list">
    <li class="item">
        <ul class="list">
            <li id="test" class="item">2</li>            


When use $("#test").closest(".item") we get second list item, but it's expected first list item.

Change History (6)

comment:1 Changed 5 years ago by San4es

In other point of view, that isn't bug if you using function .closest() considering semantic meaning of "closest" word, but documentation says "Get the first ancestor element..." and so element itself is unexpected value, because element is not equal to its ancestor, is it?

comment:2 Changed 5 years ago by ajpiano

  • Component changed from unfiled to traversing
  • Keywords needsdocs added
  • Milestone changed from None to 1.7
  • Owner set to kswedberg
  • Priority changed from undecided to low
  • Status changed from new to assigned
  • Type changed from bug to enhancement

I agree that the doc here could use a touch of refinement, but this isn't a bug - it's the way that closest has always worked since it was introduced and it is used thusly by both users and jQuery core internally for event delegation.

comment:3 Changed 5 years ago by timmywil

Docs seem pretty clear to me if one keeps reading.

comment:4 Changed 5 years ago by ajpiano

@timmywil, I agree - but the slug is still a touch on the unclear side

comment:5 Changed 5 years ago by dmethvin

  • Keywords needsdocs removed

I've updated the docs.

comment:6 Changed 5 years ago by dmethvin

  • Resolution set to fixed
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.