Side navigation
#4074 closed bug (fixed)
Opened February 05, 2009 11:55AM UTC
Closed March 18, 2009 02:49AM UTC
.clone() doesn't respect ownerDocument
Reported by: | friedcell | Owned by: | john |
---|---|---|---|
Priority: | major | Milestone: | 1.3.2 |
Component: | core | Version: | 1.3.1 |
Keywords: | clone iframe | Cc: | |
Blocked by: | Blocking: |
Description
If you clone an element from a foreign document (not the one you're executing code in), the cloned node will not have the same ownerDocument as the original element. It will instead be owned by the document where the execution happens.
elem.ownerDocument === document > false
var clone = $(elem).clone();
clone.ownerDocument === elem.ownerDocument > false (should be true)
// clone.ownerDocument === document > true (should be false)
There is a simple fix to this - the code in clone() shouldn't use document.createElement but this.ownerDocument and the call to clear should use this for context (currently uses nothing).
Attachments (0)
Change History (5)
Changed February 05, 2009 06:23PM UTC by comment:1
keywords: | → clone iframe |
---|---|
owner: | → flesler |
Changed February 15, 2009 06:43PM UTC by comment:2
resolution: | → fixed |
---|---|
status: | new → closed |
This was fixed when the recent IE clone refactoring landed.
Changed February 18, 2009 02:28PM UTC by comment:3
resolution: | fixed |
---|---|
status: | closed → reopened |
Using this.ownerDocument for createElement is a partial fix.
The call to clean() also needs the context.
That is,
return jQuery.clean([html.replace(/ jQuery\\d+="(?:\\d+|null)"/g, "").replace(/^\\s*/, "")], this.ownerDocument)[0];
I've seen the problem when using .wrap("<div></div>").
Changed February 20, 2009 12:43AM UTC by comment:4
owner: | flesler → john |
---|---|
status: | reopened → new |
I think that was mentioned on one of the tickets for this issue but it got lost. Thanks!
Changed March 18, 2009 02:49AM UTC by comment:5
resolution: | → fixed |
---|---|
status: | new → closed |
fixed in r6280