Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
Trying to eliminate children 3-7 from an element, I am looping through the array to eliminate them but it wont work

So first main has only one child which is why I selected the child blades as var blades = main.children[0]; then I am trying to loop through and just eliminate the children within blades from [3] through [7] but for some reason when doing this on the console it won't work.

 function deleteBlades() {
        var main = document.getElementById("id-9a1e3f8f48548d4c2c422b1f92cb749a");
        var blades = main.children[0];
        for (var i = 0; i < blades.length; i++) {
            if( i >= 3 || i <= 7)
                {
                    blades.children[i].remove();
                }
        }
    }
    deleteBlades();

Any ideas on what am I doing wrong?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

in your for loop you are reading blades.length when it is a HTMLElement not array, use blades.children.length instead

 function deleteBlades() {
    var main = document.getElementById("id-9a1e3f8f48548d4c2c422b1f92cb749a");
    var blades = main.children[0];
    for (var i = 0; i < blades.children.length; i++) {
        if( i >= 3 || i <= 7)
            {
                blades.children[i].remove();
            }
    }
}
deleteBlades();
about 4 years ago · Juan Pablo Isaza Relatório

0

Looks like you got a typo in your loop.

I think what you meant to do is:

for (var i = 0; i < blades.children.length; i++) {
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda