Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda