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

303
Visualizações
Difference between insertAdjacentElement() and insertBefore()?

I'm trying to understand the error DOMException: Node.insertBefore: Child to insert before is not a child of this node which I've seen in both React and Angular projects over time and I started wondering: why does it even matter if an element A is "a child of" element B? Why choosing Node.insertBefore() over Element.insertAdjacentElement()?

The way I see it, both have browser support for ages and both work for SVG. But Node.insertBefore() seems to have an awkward API to me, because it requires to specify the parent.

Am I missing something?

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

0

insertBefore() requires you to provide the parent node, an existing child node, and the new node to be inserted; the new node is put before the child node. The child node has to be an immediate child of the parent node, otherwise you get that error.

insertAdjacentElement only requires you to provide an existing node and the new node. The new node is inserted at some place related to the existing node. There's no need to provide the parent node.

insertAdjacentElement() is newer than insertBefore(), but both have been around for some time.

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