Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!