I have found posts that suggest a solution to how to remove an element: first, getElementById()
, then use .remove()
method.
Suppose I have many elements that belong to a class className
. I have to do a for
loop to get each id in order to remove them all.
Is there a faster way to apply remove()
on a className
? I have tried the below code and it does not work (i.e. all the elements do not get deleted).
let elementGrp = document.getElementsByClassName('my-class-name');
elementGrp.remove();