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

145
Vistas
How to apply CSS to newly loaded Document

I would like to load a document using fetch() and then apply CSS styles to it.

However, it doesn't seem like I can inspect the styles unless I append the document to the main one, as seen here:

const doc = fetch(); // get some document

doc.documentElement.computedStyleMap()  // returns an empty map

document.appendChild(doc.documentElement)  // attach it to the main document object

doc.documentElement.computedStyleMap()  // now populated

Is there any way I can call some method to get the CSS cascade to happen, populating the computedStyleMap without attaching it as done in step 3?

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

0

I would like to load a document using fetch() and then apply CSS styles to it.

I've tested this locally and it seems computedStyleMap only works for documents / elements that are actually attached in the DOM.

An alternative is using the styleSheets API.

    var styleSheet = document.styleSheets[0];
    styleSheet.insertRule('.myclass{ color: 'red'; }', styleSheet.cssRules.length);

Keep in mind that if you load a stylesheet from another domain, like a CDN, you may need to select a different index of the .styleSheets to use one on your domain. Otherwise you may encounter security errors.

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