nyildizian Posted May 28, 2009 Share Posted May 28, 2009 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 More sharing options...
chibineku Posted May 28, 2009 Share Posted May 28, 2009 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 More sharing options...
nyildizian Posted May 28, 2009 Author Share Posted May 28, 2009 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.thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.