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

157
Views
How would one successfully change the font of a header/paragraph in javascript?

Hope you're having a great day. I'm trying to make my site more accessible, but I really love this one font. However, it's hard to read for some people. I'm making a button to change all the fonts to an easier to read font, but I'm having trouble creating that code.

I've tried document.getElementById('header').style.fontFamily = "font-family: 'Rambla', sans-serif" (and all of the other DOM selectors there too), But they either don't work with no errors, or it errors.

Here's a snippet of my code:

function fontChange() {
  document.getElementById('header').style.fontFamily = "font-   family: 'Rambla', sans-serif"
  console.log('Works?')
}
<h1 id="header">What are the parameters for the /scheme command?</h1>
<button id="fontChange" onclick="fontChange()">
  🦽
</button>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I advice you to toggle a global class on body element for example.

document.body.classList.add('accessible-font');

Then it would give you more possibilities and easier integration using some stylesheets :

.accessible-font #header {
  font-family: 'Rambla', sans-serif";
}

You can then define some global or specific rules based on this global class. It also allows you to easilly switch between a11y ON / OFF.

about 4 years ago · Juan Pablo Isaza Report

0

try this ?

    <h1 id="header">What are the parameters for the /scheme command?</h1>
<button id="fontChange" onclick="fontChange()">
  🦽
</button>
<script>
    function fontChange() {
           document.getElementById('header').style.fontFamily = "Rambla"
        console.log('Works?')
    }
</script>
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!