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

119
Vistas
Run a function after CSS link's media attribute is changed

I'm trying to dynamically change the media attribute of a CSS link tag and I need to run a function after the new CSS is applied.

I have a CSS stylesheet link tag

<link href="print.css" rel="stylesheet" media="print">

Inside my JavaScript code, I want to change the media attribute from print to all, and after the new style changes are applied to my page, I need to run a function.

Right now, I'm doing the following:

if (myCSSlink.getAttribute("media") === "print") {
                myCSSlink.setAttribute("media", "all");
                myCSSlink.onload = () => {
                    //do some work
                };

}

At this point, I'm assuming that after the media attribute is changed, the CSS loads again. But my code inside the anonymous arrow function doesn't seem to work. How can I approach this?

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

0

You should assign an onload handler to do both - change the media attribute and run your custom onload function.

function onLoad(link) {
    link.setAttribute('media', 'all');
    yourCustomFunction();
}
<link href="print.css" rel="stylesheet" media="print" onload="onLoad(this);">

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