So I'm writing some code for a grease-monkey bot but on the site the bot is for the JavaScript function splice() is not recognized and does absolutely nothing when run. The array I'm using consists of about 100 or so different elements all got from the web page and I then need to sort them removing certain elements if they have a certain style as in... (Variables were initialized earlier)
list = document.getElementById("raffles-list").children;
while (a > list.length) {
if (list[a].style != "") {
list.splice(a, 1);
a++;
}
}
I know it is nothing to do with my computer as I was able to splice on other web sites so is there a way that I can remove the element without splice or is there a way I can get it to work on the website?
It happens, because Node.children
returns HTMLCollection
, that is no an array and doesn't have splice method - for more information look MDN.
You can use Array.prototype.splice.call(list, a, 1)
, this must do the thing.