title: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node
body: <p>I'm trying to insert a comment node before the particular node (<code>&lt;name&gt;</code>) in my xml. Here is the method for it:</p>
  
  <pre><code>function test(xmlResponse)
  {
      var parser = new DOMParser(), xmlDoc = parser.parseFromString(xmlResponse,"text/xml");
  
      var comentDocument = document.createComment("My personal comments");
  
      console.log(xmlDoc.querySelectorAll("street name")[0])
      xmlDoc.insertBefore( comentDocument ,  xmlDoc.querySelectorAll("street name")[0]);
  
      return xmlDoc
  }
  </code></pre>
  
  <p>and when I call:</p>
  
  <pre><code>test("&lt;address&gt;&lt;street&gt;&lt;name&gt;Street name&lt;/name&gt;&lt;/street&gt;&lt;/address&gt;")
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>&lt;name&gt;Street name&lt;/name&gt;
  Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
      at Error (native)
      at generateTheComment (&lt;anonymous&gt;:12:9)
      at &lt;anonymous&gt;:2:1
      at Object.InjectedScript._evaluateOn (&lt;anonymous&gt;:895:140)
      at Object.InjectedScript._evaluateAndWrap (&lt;anonymous&gt;:828:34)
      at Object.InjectedScript.evaluate (&lt;anonymous&gt;:694:21)
  </code></pre>
  
  <p>As you can see the <code>&lt;name&gt;Street name&lt;/name&gt;</code> is getting printed correctly; as I want to append the <code>comentDocument</code> to its parent <code>&lt;street&gt;</code>. </p>
  
  <p>Not sure where I'm making mistake here.</p>
  
  <p>I'm expecting the code to return back:</p>
  
  <pre><code>&lt;address&gt;
     &lt;street&gt;
       &lt;!-- My personal comments --&gt;
       &lt;name&gt;Street name
       &lt;/name&gt;
     &lt;/street&gt;
  &lt;/address&gt;
  </code></pre>