JavaScript font size adjustment

Have you ever wanted to change the size of the font within web page with just the click of a button?

You would place this somewhere in the page:

<script type="text/javascript">
function f(n) {
	document.body.style.fontSize = n;
	x=document.getElementsByTagName("td");
	for (i=0;i<=x.length;i++){
		x[i].style.fontSize = n;
	}
}
</script>

To use it you would use something like this:

<a href="#" onClick="f('15px'); return false;">Set font size to 15px</a>
<a href="#" onClick="f('12px'); return false;">Set font size to 12px</a>
<a href="#" onClick="f('10px'); return false;">Set font size to 10px</a>

Example:

Set font size to 15px
Set font size to 12px
Set font size to 10px

Share this