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

176
Vistas
JavaScript - Create elements using web component class

I have a web component that only works when some properties are set, when I create the component with Document.createElement() I can't pass properties then an error happens in my component.

Is it possible to create the component by creating an instance of the component class or something similar and be able to pass parameters to it's constructor?

customElements.define('x-card', class extends HTMLDivElement {
//...
}, { extends: 'div' });

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

0

You can create a new instance using new WCard. This requires having access to the class though.

Please note that custom element names preferrably should not start with x-.

So change your code:

export class WCard extends HTMLDivElement {
//...
}

customElements.define('w-card', WCard, { extends: 'div' });

window.WCard = WCard;

This allows you to call new on the class globally, or if your code imports the class.

const wcard = new WCard(...args);
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