Consider the following code.
Inside of "videos_list" element i have a list of elements that i get in "couple" variable. I'm trying to remove all elements who have a attribute "ai" different of "list_couple"(to test i put only one element). The problem is, when he find the element, he doesn't delete the other elements after the found element.
Example to illustrate the idea: Consider the list ("x", "r", "t", "b", "h", "p") and the id="t".
What he is doing is ("_", "_", "t", "b", "h", "p").
He should do ("_", "_", "t", "_", "_", "_") or ("t").
Why the value of "i" is toggling between 0 and 1 after he finds the element? I see this with alert() function in the example. The problem is in "while" loop, i believe.
var clicked = 0;
var interval = setInterval(function( ) {
var list_couple = new Array("2583521"),
clicks = 1,
videos = document.getElementById( "videos_list" ),
couple = videos.getElementsByTagName( "a" );
var i = 0;
while( i < couple.length ) {
var flag = 0;
//alert(i);// To see the value of the i.
for(j = 0; j < list_couple.length; j++) {
if((couple[i].getAttribute( "ai" )) == list_couple[j]) {
flag = 1;// Element found.
i++;
break;
}
}
if( !flag ) {
videos.removeChild( couple[i].parentNode );
}
}
document.getElementById('btnMoreVideos').click();// Click on the button.
clicked++;
if(clicked >= clicks) {
clearInterval( interval );
}
}, 1000);
What am i doing wrong?
Array.filter?