This script changes the font size (& lt; P & gt; label) of any text in a paragraph ). If you want to change part of the getElementsByTagName (& quot; P & quot;); edited text in other labels. To use this code to access your webpage, you must use a pixel font (PX) instead of a relative font, either "EM" or "% ". Of course, if you use code of other font units, you can easily adapt to this. If the script cannot find the font size of a paragraph, it will be 12px by default.
Core code:
The Code is as follows:
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 on your web page (whether it is placed in the header, or placed in an external JS file and imported ). Then you can call the function to increase or decrease the font size like the following.
Usage:
The Code is as follows:
-
+