views:

152

answers:

2

I found the following script for increase and decrease font size but does anyone have any idea how to do the function for default font?

var min=8;
var max=18;
function increaseFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;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('div');
   for(i=0;i<p.length;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"
   }   
}
+2  A: 
function resetToDefaultFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      p[i].style.fontSize = "12px";
   }
}

Note: jQuery could make all these functions into 3 one-liners, so you might want to look into it.

www.jquery.com

Stefan Kendall
have tested it. It working fine. Thanks iftrue for the speedy respond
Caremy
A: 

This is fine if all your page is set to 12px, but how can I set the reset button to take into account of differing text sizes on the same page?