Skip to content

Commit ccf0550

Browse files
committed
Fixed clone so that it now properly copies changes to the innerHTML in IE. Unfortunately, IE stores some modifications to some attributes only as a property and they are still not copied properly. This is documented in ticket #1836.
1 parent b3ec8ed commit ccf0550

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/core.js

Lines changed: 17 additions & 3 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -292,9 +292,23 @@ jQuery.fn = jQuery.prototype = {
292
clone: function( events ) {
292
clone: function( events ) {
293
// Do the clone
293
// Do the clone
294
var ret = this.map(function(){
294
var ret = this.map(function(){
295-
return this.outerHTML ?
295+
if ( jQuery.browser.msie ) {
296-
jQuery( this.outerHTML )[0] :
296+
// IE copies events bound via attachEvent when
297-
this.cloneNode( true );
297+
// using cloneNode. Calling detachEvent on the
298+
// clone will also remove the events from the orignal
299+
// In order to get around this, we use innerHTML.
300+
// Unfortunately, this means some modifications to
301+
// attributes in IE that are actually only stored
302+
// as properties will not be copied (such as the
303+
// the name attribute on an input).
304+
var clone = this.cloneNode(true),
305+
container = document.createElement("div"),
306+
container2 = document.createElement("div");
307+
container.appendChild(clone);
308+
container2.innerHTML = container.innerHTML;
309+
return container2.firstChild;
310+
} else
311+
return this.cloneNode(true);
298
});
312
});
299

313

300
// Need to set the expando to null on the cloned set if it exists
314
// Need to set the expando to null on the cloned set if it exists

0 commit comments

Comments
 (0)