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

164
Vistas
Custom HTML element that behaves like the built-in <div> elment

I want to create a custom HTML element that behaves exactly like the built-in <div> element. I'm trying to prevent a <div> soup. I would for example want to have a <currency-list> element. This element should behave exactly like the <div> element. The only difference is the name. How can I achieve this?

Thanks, Yosemite

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

0

a DIV (HTMLDivElement) is a block element.

But you don't even need a defined Custom Element/Web Component to make a block element

customElements.define("currency-list", class extends HTMLElement {
  connectedCallback() {
    this.style.display = "block";
  }
});
another-list {
  display: block;
}

body>*:defined {
  background: green;
  color: beige;
}

body>*:not(:defined) {
  background: lightgreen;
}
Line 1
<currency-list>Hello Web Component</currency-list>
Line 3
<div>Line 4</div>
Line 5
<another-list onclick="alert(this.constructor.name)">Line 6</another-list>
Line 7

Notes:

  • <currency-list> is an "Autonomous Custom Element" (extends HTMLElement)

  • You can extend HTMLDivElement in Chromium and FireFox, but Apple has stated they will never implement "Customized Built-In Elements"
    From: https://github.com/WICG/webcomponents/issues/509

  • <another-list> is an HTMLUnknownElement; nothing wrong with using it, its constructor is an HTMLElement, so can do everything an HTMLElement can do.
    For more on the value of Unknown Elements see my Dev.to post

  • You can set any CSS display value on a DIV, you can't on your own Elements, as it will destroy the display:block setting.

PS. tag your SO questions web-component and/or custom-element

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