title: Replace a node with a duplicate using JavaScript
body: <p>I have a <code>div</code> element and I need to make a "backup" of it, to restore in certain occasions.</p>
  
  <p>To clone the <code>div</code>, I'm using:</p>
  
  <pre><code>savedDiv = originalDiv.cloneNode(true);
  </code></pre>
  
  <p>And to restore it:</p>
  
  <pre><code>originalDiv.parentNode.replaceChild(savedDiv,originalDiv);
  </code></pre>
  
  <p>The problem is that I get <code>Uncaught TypeError: Cannot read property 'replaceChild' of null
  </code>
  Any elegant way to solve this issue?</p>