Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11353 closed bug (invalid)

$.contains returns true if elements are different and lack 'contains' methods

Reported by: [email protected] Owned by:
Priority: low Milestone: None
Component: misc Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:



elem1 = $('<div></div>'); elem2 = $('<p></p>');

$.contains(elem1, elem2); = true $.contains(elem2, elem1); = true

Change History (4)

comment:1 Changed 11 years ago by sindresorhus

Component: unfiledmisc
Priority: undecidedlow
Resolution: invalid
Status: newclosed

$.contains docs:

Check to see if a DOM element is within another DOM element.

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

comment:2 Changed 11 years 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 11 years ago by [email protected]

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 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.

Note: See TracTickets for help on using tickets.