when Im cloning an object in javascript by doing object.cloneNode(true) the parentNode is null in the new copy. Im trying to set it but with no success. my code look like this:
old_DataRoot = DataRoot.cloneNode(true);
old_DataRoot.parentNode=DataRoot.parentNode.cloneNode(true);
also tried:
old_DataRoot = DataRoot.cloneNode(true);
old_DataRoot.parentNode.appendChild(DataRoot.parentNode.cloneNode(true));
both options give me "old_DataRoot.parentNode is null or not an object" what am I doing wrong?
thanks alot, Yoni.
old_DataRoot? You should probably describe what you're ultimately trying to accomplish..parentNode? Is it so you remember where to re-insert it? If so, just make a variable reference to the parent.var backup = DataRoot.cloneNode(true); var backup_par = DataRoot.parentNode;Then later, you can insert the backup.backup_par.appendChild(backup);or you can do a.replaceChildfrom the parent:backup_par.replaceChild(backup, DataRoot);DataRoot.selectSingleNode("//Users/*[@Id = \"" + NodeID + "\"]");and without a parent it doesnt seem to work. the XML look like this<Users> <User Id="m2" Email="" RealName="m2"/> <User Id="m3" Email="" RealName="m3"/> <User Id="m6" Email="" RealName="m6"/> <UsersSearch SearchText="m1"/> </Users>