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.