Simple ES6 answer:
document.querySelectorAll('.classname').forEach(e => e.remove());
Explanation:
- document.querySelectorAll() loops through the elements in the document returning a NodeList of all elements with the specified selector (e.g.
'.class', '#id', 'button')
- forEach() loops through the NodeList and executes the specified action for each element
- e => e.remove() removes the element from the DOM
Note, however, that this solution is not supported by Internet Explorer. Then again, nothing is.