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

174
Vistas
Is it possible to use ECMAScript modules (ESM) in SVG documents?

Or will it be supported in future versions of browsers? I've been thinking about this and tried to read up on the topic, but I couldn't figure it out. I also tried the following (which did not work in either Chrome 96 or Safari 14):

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" xml:space="preserve">

    <script type="module">
        import { demo } from './demo.js'

        const test = new demo();
        console.log('x', test);
    </script>

    <rect x="0" y="0" width="50" height="50" />
</svg>

Is it possible? Will it be possible? Is there a workaround?

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

0

Very basic example

customElements.define("svg-component", class extends HTMLElement{
  connectedCallback(){
    this.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" xml:space="preserve">
    <rect x="0" y="0" width="50" height="50" fill="${this.getAttribute('fill')}" />
</svg>`;
    // Your JS here
  }
});
svg-component{
  width:150px;
  display:inline-block;
}
<svg-component fill="red"></svg-component>
<svg-component fill="yellow"></svg-component>
<svg-component fill="blue"></svg-component>

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