Article From:https://www.cnblogs.com/xuchao0506/p/9970173.html

Simple Description: Recently I uploaded a picture, when uploading the echo picture, I need to click on the picture, delete the effect from the page, and then I found the removeChild () method. To be honest, when I saw it, I thought this problem had been solved, but I found this one.The parameters passed in the method are somewhat unusual. I put an ID string wrapped in quotation marks inside to denote deletion of the ID. As a result, an error occurred in F12.,Then I first wondered if I misspelled my string, and then I took the attitude of trying. I removed the quotation marks and put the ID string directly, and the result would be good.

 The final results are as follows:

 

 

Other examples:

//htmlCode
<div id="parentDiv">
  <img src=rootPath+"/assets-new/apps/img/shanchu.jng" alt="">
  <h1>Test Text & lt; / H1 & gt;
  <input type="text" name="test"/>
  <span>spanLabel & lt; / span & gt;
</div>

//jsCode
var parent = document.getElementById("parentDiv");
parent.removeChild(parent.childNodes[1]);//Delete subscripts from 0 to start & lt; H1 & gt; test text & lt; / H1 & gt;

var item = parent.removeChild(parent.childNodes[3]);


Summary: The removeChild (Node) parameter is a node node object, which is very important!!!

 

Leave a Reply

Your email address will not be published. Required fields are marked *