Side navigation
#6793 closed enhancement (invalid)
Opened July 15, 2010 02:59PM UTC
Closed December 02, 2010 08:08AM UTC
Last modified March 13, 2012 11:08PM UTC
jQuery clone without innerHTML workaround for IE
| Reported by: | steida | Owned by: | steida |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.4.3 |
| Component: | core | Version: | 1.4.2 |
| Keywords: | clone cloneNode ie bug | Cc: | |
| Blocked by: | Blocking: |
Description
Its pretty old fix from hedgerwang, rewamped for jQuery.
Attachments (0)
Change History (4)
Changed July 21, 2010 01:28AM UTC by comment:1
Changed October 31, 2010 01:39AM UTC by comment:2
| owner: | → steida |
|---|---|
| priority: | → undecided |
| status: | new → pending |
Could you please explain what specific issues this code is addressing?
Changed October 31, 2010 05:17PM UTC by comment:3
Read the comments you moron.
"IE copies events bound via attachEvent when cloneNode."
Instead of innerHTML, use clearAttributes.
Changed December 02, 2010 08:08AM UTC by comment:4
| resolution: | → invalid |
|---|---|
| status: | pending → closed |
Automatically closed due to 14 days of inactivity.
Code from the link:
// jQuery clone fix for Internet Explorer events clonning issue, added deep option // daniel.steigerwald.cz 2010, MIT licence jQuery.fn.clone = function (events, deep) { // Do the clone var ret = this.map(function () { if (!jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this)) { // IE copies events bound via attachEvent when // using cloneNode. Calling detachEvent on the // clone will also remove the events from the orignal // In order to get around this, we use innerHTML. // Unfortunately, this means some modifications to // attributes in IE that are actually only stored // as properties will not be copied (such as the // the name attribute on an input). var clone = this.cloneNode(!!deep), froms = [this].concat(deep ? this.getElementsByTagName('*') : []), tos = [clone].concat(deep ? clone.getElementsByTagName('*') : []); for (var i = tos.length; i--; ) { var to = tos[i], from = froms[i]; // this method remove attached events to.clearAttributes(); // this method merge all attributes except events to.mergeAttributes(from); // retain selected options if (from.options) { var toOptions = to.options, fromOptions = element.options; for (var j = no.length; j--; ) toOptions[j].selected = fromOptions[j].selected; } // fix some browsers inconsistenses var attr = { input: 'checked', option: 'selected', textarea: 'value' }[this.tagName.toLowerCase()]; if (attr && from[prop]) to[prop] = attr[prop]; }; return clone; } else { return this.cloneNode(!!deep); } }); // Copy the events from the original to the clone if (events === true) { cloneCopyEvent(this, ret); cloneCopyEvent(this.find("*"), ret.find("*")); } // Return the cloned set return ret; };