-1

I try to remove my links one by one from div id="wrapper". But it doesn't work:

window.onload = function () {
  setInterval(function () {
    var wrapper = document.getElementById("wrapper");
    var my_links = wrapper.getElementsByTagName("a");

    var i;
    for (i = 0; i < my_links.lenght + 1; i++) {
      my_links.splice(0, i);
    }
  }, 5000);
}

What is the problem? How can i fix my snippet?

Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191

1 Answers1

1

Typo here and length + 1 should be length - 1:

for (i=0; i<my_links.lenght+1; i++){

should be:

for (i=0; i<my_links.length-1; i++){

Further more

Look at this question over here to find the remove function you are looking for: Remove element by id

So it will be:

for (i=0; i<my_links.length-1; i++){
    my_links[i].remove();
}

Remove function only works with the function of the question I posted.

Community
  • 1
  • 1
Niels
  • 48,601
  • 4
  • 62
  • 81