I am new to JavaScript prototype and closure, following is my code:
function setFontSize(size) {
return function() {
console.log("font size: "+size+ " setFontSize()");
document.body.style.fontSize = size + 'px';
};
}
function setFontSizeInput(ipval) {
console.log("font size ipval : "+ipval);
var fontsizeIP= setFontSize(ipval);
}
window.onload = function() {
var fontsize18 = setFontSize(18);
var fontsize14 = setFontSize(14);
var fontsize16 = setFontSize(16);
document.getElementById('size-18').onclick = fontsize18;
document.getElementById('size-14').onclick = fontsize14;
document.getElementById('size-16').onclick = fontsize16;
}
On onkeyup event I am calling setFontSizeInput, as the user enters value in input field I want to change fontsize so I have created new object of setFontSize(ipval) and passed input field value, but it not reflecting. Any idea whats wrong in my code?