I use this script to find out IDs of elements in a class and then delete them
var ids = [];
var eic = document.getElementsByClassName('classname');
for(var i = 0, length = eic.length; i < length; i++) {
ids.push(eic[i].id);
$('#'+eic[i].id).remove();
}
The problem is that when I am trying to delete them, it deletes only some of the elements and the console is returning an error:
"TypeError: eic[i] is undefined"
When I am not trying to delete them, no error is returned and when I alert gained IDs there is every single one.