I need to remove all the elements with a certain class. I searched and tried most of the options but didn't make it work on IE11, i am aware of IE doesn't support remove() native Javascript function but does support removeChild(). With removeChild() i get the following message: " Object doesn't support property or method 'removeChild'".
html:
<div class "main">
<div class "contentHolder">
<div class="contentInfo">some text</div>
<div class="contentTxt">some text</div>
<div class="contentTxt2">some text</div>
</div>
<div class "contentHolder">
<div class="contentInfo">some text</div>
<div class="contentTxt">some text</div>
<div class="contentTxt2">some text</div>
</div>
<div class "contentHolder">
<div class="contentInfo">some text</div>
<div class="contentTxt">some text</div>
<div class="contentTxt2">some text</div>
</div>
</div>
I want to remove all the divs with the class contentInfo this script is working in all browsers but IE11. I understand that its because .remove() is not supported.
const elements = document.getElementsByClassName('contentInfo');
while (elements.length > 0) elements[0].remove();
So I tried but it only works on the first contentHolder.
var i;
for (i = 0; i < elements.length; i++) {
elements[i].parentNode.removeChild(elements[i]);
}
Another thing that I dont understand is: why the below line is working while it's using .remove()? I use it to remove a class of the menu.
menu.classList.remove('desactive');