Ticket #11353 (closed bug: invalid)
$.contains returns true if elements are different and lack 'contains' methods
| Reported by: | rjberry@… | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | misc | Version: | 1.7.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
e.g.
elem1 = $('<div></div>'); elem2 = $('<p></p>');
$.contains(elem1, elem2); = true $.contains(elem2, elem1); = true
Change History
comment:1 Changed 15 months ago by sindresorhus
- Priority changed from undecided to low
- Resolution set to invalid
- Status changed from new to closed
- Component changed from unfiled to misc
comment:2 Changed 15 months ago by dmethvin
In general a non-chained method like $.method usually accepts a DOM element, not a jQuery object. It's intended as a low-level method.
comment:3 Changed 15 months ago by rjberry@…
Should it not return false then or even better throw an error? Why do JavaScript libraries so rarely throw errors? Is this against some kind of policy?
comment:4 Changed 15 months ago by dmethvin
The reason that JavaScript APIs don't usually throw errors intentionally is that it is expensive to check all the argument counts and types. Instead, we document the valid inputs and outputs of the API at http://api.jquery.com . I don't know what $.contains([{}], {}) or $.contains(new Date, "March", 4) does but those are not valid calls.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

$.contains docs:
$.contains doesn't support jQuery objects, only vanilla DOM elements.