#11187 closed bug (fixed)
jQuery.find() returns unexpected result in Safari
Reported by: | maspwr | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | selector | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Using jQuery.find() with an element as the argument returns a jQuery object representing that element, even if the element has been removed from the DOM. The expected behavior is for find() to return an empty list after the element has been removed from the DOM.
The unexpected behavior has been observed in Safari 5.1.2 (7534.52.7). The expected behavior has been observed in Chrome 16.0.912.75 and FireFox 8.0.1.
A short example is pasted below. You can try out two examples of this at the following links: http://jsfiddle.net/jYbvU/ http://jsfiddle.net/UpWMV/
<div id='foo'> <div id='bar'>Click Me</div> </div>
$(document).on('click.weird', function(event) { console.log($(document).find(event.target)); }); $('#bar').on('click', function(event) { $('#foo').html('<h1>Replaced</h1>'); console.log('Replaced "#foo"'); });
Change History (8)
comment:1 Changed 11 years ago by
Component: | unfiled → selector |
---|---|
Priority: | undecided → high |
comment:2 Changed 11 years ago by
Just to continue the debugging, the phenomenon doesn't occur with pure DOM:
comment:3 Changed 11 years ago by
One more example. Searching from 'html' instead of document does not find the element.
http://jsfiddle.net/maspwr/pEKca/
This suggests to me that it has been removed from the DOM tree to some extent, but it is still represented in the document somehow.
comment:4 Changed 11 years ago by
Priority: | high → low |
---|---|
Status: | new → open |
Okay, more stuff dumped:
Still fishy in Safari. When a DOM element is used in .find()
we take the element and use .contains
or .compareDocumentPosition
to see if it is within the jQuery set. It seems like Safari implements .contains
but we should be checking .compareDocumentPosition
instead, perhaps we need to change the order in Sizzle?
comment:5 Changed 11 years ago by
I cant't get acess content of iframe in the same domain, using Google Chrome 17. It isn't works:
$('iframe').contents().find('body').height();
I want resize the iframe using the content of iframe height.
comment:7 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
This is interesting, take a look at a modified version of the test... http://jsfiddle.net/rwaldron/R8SMW/
It might not be something we can address, my first thought is that the event handler is firing before the node is actually removed.