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

148
Views
click event doesn't change font size

I have this code:

<!DOCTYPE html><html><head></head><body>

<button id="b12">12px</button>
<button id="b14">14px</button>
<button id="b16">16px</button>

<script>
document.getElementById('b12').onclick = clickHandler(12)
document.getElementById('b14').onclick = clickHandler(14)
document.getElementById('b16').onclick = clickHandler(16)
function clickHandler(size) {
    return function() {
        document.body.style.fontSize = `${size}px`
    }
}
</script>

</body></html>

But the buttons font size doesn't seem to change when I click one. I also made a codepen here: https://codepen.io/trufo/pen/eYedaLE If anyone could tell me what I'm missing in that code, that would be greatly appreciated.

That didn't solve it. It's a different type of question. Mine is pertaining to why the click does not activate the function. Whereas that other one is about why does the event fire up even when nothing is clicked.

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!