#7297 closed bug (invalid)
Firefox jQuery contains method error
Reported by: | Owned by: | ||
---|---|---|---|
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
Change History (10)
comment:1 Changed 13 years ago by
Keywords: | firefox method error added |
---|---|
Owner: | set to oleg.richards@… |
Priority: | undecided → low |
Status: | new → pending |
comment:2 Changed 13 years ago by
Breaks on Firefox 3.6.12 (Mac OSX Snow Leopard): http://jsfiddle.net/gRyZp/
comment:3 Changed 13 years ago by
Sorry, missing a # in the first selector (doesn't particularly affect outcome though). Here is a better example : http://jsfiddle.net/gRyZp/1/
comment:4 Changed 13 years ago by
Component: | unfiled → core |
---|---|
Milestone: | 1.5 → 1.4.5 |
Priority: | low → high |
Status: | pending → open |
Confirmed; Doesn't return in FF3.6.12
comment:5 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | open → closed |
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.
comment:6 Changed 12 years ago by
Version: | 1.4.3 → 1.5 |
---|
There wasn't a 1.4.5 release, was actually 1.5.
comment:7 Changed 12 years ago by
Milestone: | 1.4.5 → 1.5 |
---|
There was no 1.4.5 release, was actually 1.5.
comment:8 Changed 12 years ago by
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.
comment:10 Changed 12 years ago by
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
Could you please submit a complete test-case on jsFiddle.net that reproduces this issue so that we can accurately evaluate the bug experienced?