Skip to main content

Tedshd's Dev note

JavaScript - delete element

Table of Contents

# JavaScript - delete element

I use this way.

var dom = document.querySelectorAll('.dom');

for (var i = 0; i < dom.length; i++) {
    dom[i].outerHTML = '';
    delete dom[i];
};

// or

var dom = document.querySelector('#dom');

var dom = document.querySelector('h1');

dom.outerHTML = '';
delete dom;

If use IE document.querySelector only use IE8 up

Refer - JavaScript: remove element by id