Bug Tracker

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#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:


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>
$(document).on('click.weird', function(event) {

$('#bar').on('click', function(event) {
    console.log('Replaced "#foo"');

Change History (8)

comment:1 Changed 11 years ago by Rick Waldron

Component: unfiledselector
Priority: undecidedhigh

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.

comment:2 Changed 11 years ago by dmethvin

Just to continue the debugging, the phenomenon doesn't occur with pure DOM:


comment:3 Changed 11 years ago by maspwr

One more example. Searching from 'html' instead of document does not find the element.


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 dmethvin

Priority: highlow
Status: newopen

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 [email protected]

I cant't get acess content of iframe in the same domain, using Google Chrome 17. It isn't works:


I want resize the iframe using the content of iframe height.

comment:6 Changed 11 years ago by timmywil

@dmethvin: that is the plan actually.

comment:7 Changed 10 years ago by timmywil

Resolution: fixed
Status: openclosed

comment:8 Changed 10 years ago by dmethvin

#12125 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.