In order to add this code to your web page you must use pixel sized fonts (px), not relative sized fonts, use "em" or "%". Of course if you use other font units the code can be easily adapted to these. If the script cannot find the font size for a paragraph, it will default to 12px.
Core code:
var min=8;
var max=18;
function increaseFontSize() {
var p = document.getElementsByTagName('p');
for(i=0;i
if(p[i].style.fontSize) {
var s = parseInt(p[i].style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=max) {
s = 1;
}
p[i].style.fontSize = s "px"
}
}
function decreaseFontSize() {
var p = document.getElementsByTagName('p');
for(i=0;i if (p[i].style.fontSize) {
var s = parseInt(p[i].style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=min) {
s -= 1;
}
p[i].style.fontSize = s "px"
}
}
Include the above code in your web page (either place it in the header section, or place it in an external JS file and import it). You can then call functions that increase and decrease font size like below.
Usage: