This is in reference to the query about javascript cloneNode and properties.
I have observed the same issue. When using Node.cloneNode, it does not copy any properties that I manually add (as shown in the original post):
var theSource = document.getElementById("someDiv")
theSource.dictator = "stalin";
var theClone = theSource.cloneNode(true);
alert(theClone.dictator);
The cloned node, theClone
, does not retain the "dictator" property.
I have been unable to find a rationale for this behavior. The MDN documentation mentions that cloneNode
should "copy all of its attributes and their values", as specified in the DOM specification.
This inconsistency poses a challenge when attempting to create a deep copy of a DOM tree with custom properties included.
Could there be a solution or explanation that I am overlooking?