#11353 closed bug (invalid)
$.contains returns true if elements are different and lack 'contains' methods
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | misc | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
e.g.
elem1 = $('<div></div>'); elem2 = $('<p></p>');
$.contains(elem1, elem2); = true $.contains(elem2, elem1); = true
Change History (4)
comment:1 Changed 11 years ago by
Component: | unfiled → misc |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 11 years ago by
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 11 years ago by
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 11 years ago by
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.
$.contains docs:
$.contains doesn't support jQuery objects, only vanilla DOM elements.