In DOM operations, there is a removeChild method. But we need to know that even if they are deleted from the DOM in this way, they still exist. What problems will they cause? A serious problem is that all deleted nodes exist in the memory, which is the legendary Memory leakage. If dozens of megabytes are used, the operation of the browser may be affected in a few hundred times. (-Actually, I have never tested it)
So I know that you cannot delete element nodes at will. I used a useless method before. Set display to node and then delete it. I feel like I took off my clothes before killing you?
JQ has a remove method. I think it should be comprehensive. I don't know if anyone tells it whether it will cause memory problems?
You can see a method on the Internet, that is, dynamically create an empty element, drop the node to be deleted, and then clear the content in the element, so that the content can be removed from the memory.
var garbageBin;window.onload = function () { if (typeof(garbageBin) === 'undefined') { //Here we are creating a 'garbage bin' object to temporarily //store elements that are to be discarded garbageBin = document.createElement('div'); garbageBin.style.display = 'none'; //Make sure it is not displayed document.body.appendChild(garbageBin); } function discardElement(element) { //The way this works is due to the phenomenon whereby child nodes //of an object with it's innerHTML emptied are removed from memory //Move the element to the garbage bin element garbageBin.appendChild(element); //Empty the garbage bin garbageBin.innerHTML = ""; } }//To use it in your context, you would do it like this:discardElement(this);