Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
Custom HTML elements not rendering children

The following code does not render the CategoryElement's children - only the <p> element within the Shadow Root. How do I make the CategoryElement's children render?

<html>
    <head>
    </head>
    <body>
        <script>
            class CategoryElement extends HTMLElement {
                constructor() {
                    super();
                    this.attachShadow({mode: 'open'});
                    this.header = document.createElement('p');
                    this.header.innerText = 'Shadow Header';
                    this.shadowRoot.append(this.header);
                }
            }
            customElements.define('category-element', CategoryElement);

            var elem = document.createElement('category-element');
            document.body.appendChild(elem);

            var outer = document.createElement('p');
            outer.innerText = 'Outer Header';
            elem.appendChild(outer);
        </script>
    </body>
<html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I believe this gets you there, but I'm no shadow dom expert by any stretch of the imagination.

I added .shadowRoot as shown here:

elem.shadowRoot.appendChild(outer);

When I inspect with the dev tools I can see that both <p> are in side the shadow-root element (if that's the correct way to refer to it).

</head>

<body>
  <script>
    class CategoryElement extends HTMLElement {
      constructor() {
        super();
        this.attachShadow({
          mode: 'open'
        });
        this.header = document.createElement('p');
        this.header.innerText = 'Shadow Header';
        this.shadowRoot.append(this.header);
      }
    }
    customElements.define('category-element', CategoryElement);

    var elem = document.createElement('category-element');
    document.body.appendChild(elem);

    var outer = document.createElement('p');
    outer.innerText = 'Outer Header';
    elem.shadowRoot.appendChild(outer);
  </script>
</body>
<html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda