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

242
Views
Font Awesome JS

I'm using icons from "Font Awesome" and I need to use JS to change the class of the icon in question (it's for a dark/light mode), but I can't get it to work. It tells me this:"The token provided ('fa-solid fa-moon') contains HTML space characters, which are not valid in tokens."

Here is an example.

if (document.body.classList.contains('dark')) {
  localStorage.setItem('dark-mode', 'true');

  var element = document.getElementById('logo');
  element.classList.toggle('fa-solid fa-moon');

} else {
  localStorage.setItem('dark-mode', 'false');

  var element = document.getElementById('logomodo');
  element.classList.toggle('fa-solid fa-sun');
}
});

if (localStorage.getItem('dark-mode') === 'true') {
  document.body.classList.add('dark');
  btnSwitch.classList.add('active');

  var element = document.getElementById('logomodo');
  element.classList.toggle('fa-solid fa-moon');
} else {
  document.body.classList.remove('dark');
  btnSwitch.classList.remove('active');

  var element = document.getElementById('logomodo');
  element.classList.toggle('fa-solid fa-sun');
}
<i id="logo" class="fa-solid fa-sun"></i>

about 4 years ago · Juan Pablo Isaza
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!