Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda