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

90
Visualizações
Fix HTMLCollection of 4 elements but it actually shows 3 of them

i was refactoring my js code and it popped out a bug. The bug is that in a HTMLCollection of 4 elements (and if i console log them, they are ok), but if i loop them in a for, it shows me that the collection is actually 3 instead of 4. So for example an array of indexes (0,1,2,3), it shows (0,1,3) skipping the second element. I can't show much of the code because it's quite long and so my question is: why does this can happend?

console.log of the HTMLCollection:

HTMLCollection(3) [li.page-item, li#page0.page-item, li.page-item, page0: li#page0.page-item]
0: li.page-item
1: li#page0.page-item
2: li#page1.page-item
3: li.page-item
page0: li#page0.page-item
page1: li#page1.page-item
length: 4
[[Prototype]]: HTMLCollection

console.log of the length:

3

Html of pagination (i wrote a js function for create new li inside the div):

              <ul id="pagination" class="pagination flex-wrap">
                <li class="page-item"><button type="button" class="page-link" onclick="characters.deleteCharacter()">Delete</button></li>
                <li class="page-item active" id="page0" style="display: none;"><a type="button" class="page-link">0</a></li>
                <li class="page-item"><button type="button" class="page-link" onclick="characters.createCharacter()">New</button></li>
              </ul>
about 4 years ago · Juan Pablo Isaza
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