Ticket #13332 (closed bug: fixed)
.closest("*") yields input even for non-element nodes
| Reported by: | gibson042 | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 1.9.2 |
| Component: | traversing | Version: | 1.9.0 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Ref. #13265.
.closest passes text/comment/etc. nodes directly to Sizzle, which assumes all input to be elements, so .closest("*") is erroneously an identity mapping.
Change History
comment:2 Changed 3 months ago by gibson042
Indeed. This is paired with #13265 in my mind, and they should either fix or wontfix together. A fix looks like https://github.com/jquery/jquery/pull/1146.
comment:3 Changed 3 months ago by Richard Gibson
- Status changed from new to closed
- Resolution set to fixed
Fix #13265 #13332: Allow .parent/.closest with text nodes. Close gh-1146.
Changeset: 5e29ff7e59a0c97bae02b7512b40486df0f44022
comment:4 Changed 3 months ago by dmethvin
- Priority changed from undecided to high
- Component changed from unfiled to traversing
- Milestone changed from None to 1.9.2
comment:5 Changed 3 months ago by Richard Gibson
Fix #13265 #13332: traversing methods with text nodes. Close gh-1145.
Changeset: b734666f4d2e9a92b8ebb99db5b05bd4c82e71f2
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Seems like it can easily be fixed, but I suspect it hasn't been reported because it's really rare to get into that situation. For events we make sure the event target is an element, and it would seem really rare for anyone to use .contents() or serialize HTML with top-level text nodes or and then use .closest().