const allElements = document.body.getElementsByTagName('*'); for(const elem of allElements){ if(elem.className !== "") elem.remove(); // I used className here, any selector goes! }