Opened 14 years ago
Closed 14 years ago
#4074 closed bug (fixed)
.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).
Change History (5)
comment:1 Changed 14 years ago by
Keywords: | clone iframe added |
---|---|
Owner: | set to flesler |
comment:2 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 Changed 14 years ago by
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>").
comment:4 Changed 14 years ago by
Owner: | changed from flesler to john |
---|---|
Status: | reopened → new |
I think that was mentioned on one of the tickets for this issue but it got lost. Thanks!
This was fixed when the recent IE clone refactoring landed.