Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!