Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 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:

Description

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

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

(http://jsfiddle.net/QParz/1/)

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

Change History (6)

comment:1 Changed 10 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 10 years ago by ajpiano

Component: unfiledtraversing
Keywords: needsdocs added
Milestone: None1.7
Owner: set to kswedberg
Priority: undecidedlow
Status: newassigned
Type: bugenhancement

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 10 years ago by timmywil

Docs seem pretty clear to me if one keeps reading.

comment:4 Changed 10 years ago by ajpiano

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

comment:5 Changed 10 years ago by dmethvin

Keywords: needsdocs removed

I've updated the docs.

comment:6 Changed 10 years ago by dmethvin

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.