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

123
Visualizações
I’m only getting one childNode when appending nodes elsewhere

I have a page with most of the content generated from an XML file. The generated content is a table with the first cell in each row being an expanding element:

<details><summary>...</summary>...</details>

I’m trying to change the content of some <summary> into links as they are being generated. The content of the <summary> may be text or an <img> and text. Since appendChild doesn’t allow me to append a NodeList, my alternative for this was to cycle through the <summary> children and add them to the link, then append the link to a replacement <summary>. Unfortunately, the for loop never accessed the second child.

for (var j = 0; j < curSummary.childNodes.length; j++) {
  // ...
}

I verified that curSummary.childNodes.length is actually 2 but the loop only ever executed once for each <summary>. Putting an alert in to display the value of the loop variable showed it was only ever 0.

alert('there are' + curSummary.childNodes.length + ' nodes');

for (var j = 0; j < curSummary.childNodes.length; j++) { 
  alert('appending child node ' + j + ' of ' + curSummary.childNodes.length);
}

Apart from omitting the text, the code worked. The summary showed up with <img> as a link. Just to be clear, both the image and text are displayed when there isn’t a link.

And no, I’m not changing the value of the loop variable nor issuing a “break” anywhere in the loop.

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