Skip to main content

Bug Tracker

Side navigation

#7297 closed bug (invalid)

Opened October 24, 2010 08:21AM UTC

Closed December 06, 2010 05:07PM UTC

Last modified March 26, 2011 05:34PM UTC

Firefox jQuery contains method error

Reported by: oleg.richards@gmail.com Owned by: oleg.richards@gmail.com
Priority: high Milestone: 1.5
Component: core Version: 1.5
Keywords: firefox method error Cc:
Blocked by: Blocking:
Description

The following code:

var x = $('#foo');
$(document).bind('click.popup', function(e) {
 if (!$.contains(x, e.target)) {
     e.stopPropagation();
      return false;
 }

 x.trigger('popup.hide');
});

Gives me an error in Firefox. In all other browsers it works properly.

Error: g.compareDocumentPosition is not a function

Source: http://localhost:8080/public//js/libs/jquery-1.4.3.min.js

String: 102

Attachments (0)
Change History (10)

Changed October 24, 2010 03:28PM UTC by addyosmani comment:1

keywords: → firefox method error
owner: → oleg.richards@gmail.com
priority: undecidedlow
status: newpending

Could you please submit a complete test-case on jsFiddle.net that reproduces this issue so that we can accurately evaluate the bug experienced?

Changed November 07, 2010 09:26PM UTC by aaronblondeau@gmail.com comment:2

Breaks on Firefox 3.6.12 (Mac OSX Snow Leopard):

http://jsfiddle.net/gRyZp/

Changed November 07, 2010 09:28PM UTC by anonymous comment:3

Sorry, missing a # in the first selector (doesn't particularly affect outcome though). Here is a better example : http://jsfiddle.net/gRyZp/1/

Changed November 08, 2010 07:55PM UTC by rwaldron comment:4

component: unfiledcore
milestone: 1.51.4.5
priority: lowhigh
status: pendingopen

Confirmed; Doesn't return in FF3.6.12

Changed December 06, 2010 05:07PM UTC by jitter comment:5

_comment0: This isn't a bug in jQuery but rather a misunderstanding on how the contains method works. \ \ The [http://api.jquery.com/jQuery.contains/ documentation for jQuery.contains()] says: \ >'''jQuery.contains( container, contained )''' \ >'''container''' The '''DOM element''' that may contain the other element. \ >'''contained''' The '''DOM node''' that may be contained by the other element. \ \ This means you can only pass in real DOM elements to this method. In all test cases linked to on this report there are jQuery objects passed in instead which is clearly invalid. The reason it returns `true` in some other browsers is actually the real bug in the contains method.1291655278914979
resolution: → invalid
status: openclosed

This isn't a bug in jQuery but rather a misunderstanding on how the contains method works.

The documentation for jQuery.contains() says:

>jQuery.contains( container, contained )\\\\

>container The DOM element that may contain the other element.\\\\

>contained The DOM node that may be contained by the other element.

This means you can only pass in real DOM elements to this method. In all test cases linked to on this report there are jQuery objects passed in instead which is clearly invalid. The reason it returns true in some other browsers is actually the real bug in the contains method.

Changed January 31, 2011 05:53PM UTC by john comment:6

version: 1.4.31.5

There wasn't a 1.4.5 release, was actually 1.5.

Changed January 31, 2011 05:54PM UTC by john comment:7

milestone: 1.4.51.5

There was no 1.4.5 release, was actually 1.5.

Changed March 23, 2011 09:09PM UTC by anonymous comment:8

This is a real error. I get the error message also in firefox.

Error message is "a.compareDocumentPosition is not a function"

I have found a solution though... basically the error only occurs in firefox if you test to see if a jQuery object is in an element. e.g.

jQuery.contains(document, $(document.body)) //causes error in firefox

but

jQuery.contains(document, document.body) would work fine.

However the firts on works fine in other browsers.

Changed March 23, 2011 09:11PM UTC by anonymous comment:9

By the way I was using jQuery v 1.5.1 and firefox 3.6.15

Changed March 26, 2011 05:34PM UTC by anonymous comment:10

The documentation states that it only works with native DOM elements and not jQuery objects. But I agree with everyone having problems that it should accept jQuery objects as parameters.

A work-around using jQuery is:

$(contained, container).size() == 0