user3119862
user3119862

Reputation: 11

parentNode not deleting properly

my javascript knowledge is pretty poor. I'm trying to run a script with greasemonkey on http://www.twitch.tv/directory/all to remove certain kinds of streams from the list based on an image provided next to a shot of the stream(like picture of hearthstone, minecraft etc.). Here's the code:

//what you want to remove    
var killIt=["http://static-cdn.jtvnw.net/ttv-boxart/Hearthstone%3A%20Heroes%20of%20Warcraft-138x190.jpg", "http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-138x190.jpg", "http://static-cdn.jtvnw.net/ttv-boxart/Minecraft-138x190.jpg"];
var el = document.getElementsByClassName("boxart");
//runthrough elements killing certain ones
for (i = 0; i < el.length; i++) {
    for (j = 0; j < killIt.length; i++) {
        if (el[i].src == killIt[j]) {
            var ely = el[i].parentNode;
            ely.parentNode.removeChild(ely);
        }
    }
}

So i tried it on w3schools site and the code works fine, but when i try to actually run it in twitch.tv it does nothing(seemingly). Am i missing something about parent nodes? Or greasemonkey?

Upvotes: 0

Views: 50

Answers (1)

Derek 朕會功夫
Derek 朕會功夫

Reputation: 94359

The second for should be j++. Also you can use .indexOf to test if the URL is listed in the array to avoid a other for loop.

Upvotes: 2

Related Questions