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

184
Visualizações
How to get text nodes and tagged nodes out of contents of a Div element in javascript?

I have included some textual content in a div element. I want to access individual nodes out of it in the form of strings. Some nodes are tagged in bold, and therefore the rest of nodes that are formed in the text are non-tagged. I am trying to access all the individual nodes thus formed using nodeList, or through a simple indexed loop using childNode property. I have even used document.queryselectorAll(), but nothing seems to work.Following is the code snippet:

<!DOCTYPE html>
<html>
  <body>
  <div id="mydiv" class="myDiv" contenteditable="true">This <b>life</b> is my choice, <b>anyway</b> I know how to lead a good one!!!</div>
</body>
<script>
 let myString ='';
            for(let i=0; i<mydiv.childNodes.length;i++){
         myString = mydiv.childNodes[i]+mydiv.childNodes[i+1]+mydiv.childNodes[i+2]
       }
console.log(myString)
</script>
</html>

I'm getting this at the console: [object Text][object HTMLElement][object Text]

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