The function below cleans the entire contents of the parent little by little, invoking at short intervals and clearing 10 lines. It is used only when the number of lines is more than a certain value, because if you delete everything at once, the browser is suspended for a few seconds. While this object is being cleaned, the system works with the new one created in the same function.
myFunction = function() { // скрываем панель var myPanel = document.getElementById('my-panel'); myPanel.className = 'panel hide'; myPanel.removeAttribute('id'); var myPanelParent = myPanel.parentNode; // удал€ем все id внутри элемента var nodes = myPanel.querySelectorAll('*'); for (var i = 0; i < nodes.length; i++) { nodes[i].removeAttribute('id'); } // создаем другую аналогичную панель $(myPanelParent).append($('<div id="my-panel"></div>')); // внутри первой панели удаляем все строки var myRemove = function() { var myRemoveCnt = 10; // сколько элементов удаляем var myCurentEl = 0; while (myCurentEl < myRemoveCnt) { var myTrEl = myEl.querySelector('tr'); if (myTrEl !== null) { myEl.removeChild(myTrEl); } else { // если элементов для удаления больше нет myPanel.parentNode.removeChild(myPanel); // удаляем наконец сам элемент с остатком содержимого myCurentEl = myRemoveCnt; return; } myCurentEl++; } setTimeout(myRemove, 10); // перезапускаем каждые 0.01сек }; myRemove(); // запускаем удаление };
The problem is that the console with this approach displays an error on the line myPanel.parentNode.removeChild(myPanel);
that the script cannot find the parent for the element, that is, that parentNode
not defined. Why the script crashes and why only one error is caused (the script is executed quite a few times) I can not figure it out.
At first I thought that the element is decoupled from the tree and the parent element is lost (in the myPanel debug, the myPanel
value is lost) changed the code to myPanelParent.removeChild(myPanel);
but this did not save the situation, it began to swear that there are no children in the object.
var myTrEl = myEl.querySelector('tr');
where I did not find in your code the initialization of the variable myEL + preferably html code - ThisMan