Jump to content

Font Sizer Control (functionality)


nyildizian
 Share

Recommended Posts

I am using the following code in my Website/Web page to control the font size, i.e. to either increment or decrement it. The code works, however, when I first click on the increment button instead of increasing the font size it decreases it, but this happens ONLY on the FIRST initial click. Afterwards, it works as it should do, i.e. increases the font size. What I am doing wrong? Any assistance will be much appreciated.

 (in the JSHeader)var min=8;var max=18;function increaseFontSize() {var p = document.getElementsByTagName('p');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('p');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"}}[code] (on the Web page)<a href="java script:decreaseFontSize();">-</a><a href="java script:increaseFontSize();">+</a>Thanks in advance.
Link to comment
Share on other sites

I don't think you need to use the replace method on the fontsize, because parseInt will just strip out any numbers that are there anyway.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...