Reputation: 2506
I have a div
element and I need to make a "backup" of it, to restore in certain occasions.
To clone the div
, I'm using:
savedDiv = originalDiv.cloneNode(true);
And to restore it:
originalDiv.parentNode.replaceChild(savedDiv,originalDiv);
The problem is that I get Uncaught TypeError: Cannot read property 'replaceChild' of null
Any elegant way to solve this issue?
Upvotes: 1
Views: 1091
Reputation: 2506
I found the issue.
I was trying to execute this operation multiple times but it seems that, after the first time, originalDiv get's consumed.
I fixed it by initializing originalDiv
again.
Upvotes: 1