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

93
Visualizações
Insert to web-page one instance of custom HTML element more than once

As example, I dynamically create instance of some custom HTML element. After this, I twice use document.body.appendChild() and this work, but this should no be. What I may do for prevent this?

I put sample about this situation below in the text. RandomParagraphSizePlaceholder is simple web-component from some book. I use it only for illustration purposes.

enter image description here

https://jsfiddle.net/h6cxjae5/

P.S. I see, that is something wrong with web component, may be.

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

0

Only one instance of web component exists in web-page. But web component content is duplicated. May be, because it created in connectedCallback. I dont very famimiliar with web component :(.

about 4 years ago · Juan Pablo Isaza Relatório

0

You get two instances, because your code:

 this.appendChild(document.importNode(placeholder.content, true));

effectively makes a copy (importNode) and then appends another element.

connectedCallback (corretcly running twice) has (in this case) nothing to do with it.

https://developer.mozilla.org/en-US/docs/Web/API/Document/importNode

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