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

285
Vistas
How to change the background colors of all <em> elements

I am trying to change the background colors of all italized text, instead of using a span on every single word through the paragraph. It says <em> next to the italized text. I have tried

$(".em").css({
    "background-color":"#d9f9f9",
});

or/and tried this:

var elem=document.getElementByTagName(em)[1];
elem.style.backgroundColor='#d9f9f9';
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

See querySelectorAll:

Notices this method return an array, so we should loop it:

var emList = document.querySelectorAll('em');

[].forEach.call(emList , function(em) {
  // do whatever
  em.style.color = "red";
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

Your first suggestion says ".em" where it should say "em". Your seconds suggestion says em where it should say "em".

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could try the following:

const italics = document.querySelectorAll('em');

italics.forEach(italic => {
  italic.style.backgroundColor = '#d9f9f9';
});
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