Usuwanie z html
Za pomocą setTimeout odpalam funkcję, która cyklicznie tworzy nowy element, dodaje go do tablic, a następnie usuwa go z html. Otwórz konsolę debugera oraz przeanalizuj kod html
const elements = [];
function makeEl() {
const div = document.createElement('div');
div.classList.add("test");
div.innerText = "Jestem nowym elementem";
elements.push(div); //dodaję do tablicy
document.body.appendChild(div); //dodaję do html
setTimeout(() => {
div.remove(); //usuwam TYLKO z html
setTimeout(() => {
console.log(elements);
makeEl();
}, 1000)
}, 1000)
}
makeEl();