Codesnipp.it Social Code Sharing

Amber Weinberg

Another Simple Text Resizer

by Amber Weinberg on Dec 27, 2011

/* Thanks to http://www.white-hat-web-design.co.uk/blog/controlling-font-size-with-javascript/, this is more browser friendlly*/ var min=16; var max=22; function increaseFontSize() { var p = document.getElementsByTagName('article 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 = 16; } 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 = 16; } if(s!=min) { s -= 1; } p[i].style.fontSize = s+"px" } } <p><a class="smaller" href="javascript:decreaseFontSize();">A</a><a class="larger" href="javascript:increaseFontSize();"><span>A</span></a></p>

Can't see the comments? Please login first :)