I have this code to change the font size of a paragraph with 3 buttons. I would like to know which method can I use to not repeat the same lines and make this code more compact.
window.addEventListener('load', inicio, false);
function inicio(){
var boton1 = document.getElementById('boton1');
var boton2 = document.getElementById('boton2');
var boton3 = document.getElementById('boton3');
boton1.addEventListener('click', fuente10, false);
boton2.addEventListener('click', fuente13, false);
boton3.addEventListener('click', fuente20, false);
}
function fuente10(){
var parrafo = document.getElementById('parrafo');
parrafo.style.fontSize='10px'
}
function fuente13(){
var parrafo = document.getElementById('parrafo');
parrafo.style.fontSize='13px'
}
function fuente20(){
var parrafo = document.getElementById('parrafo');
parrafo.style.fontSize='20px'
}
I was thinking in a for loop but I can't figure it out how to do it :/