Can you fix this please (Javascript)

Associate
Joined
28 Feb 2007
Posts
969
Location
Leeds/Sunderland
Can someone help me fix this because it only works in IE but i want it to work in FF and IE.
The code it to change the font size when you click the size you want.

Code:
<script language="javascript" type="text/javascript">

var fontSize = new Array();

fontSize[2] = 12;
fontSize[3] = 14;
fontSize[4] = 16;
fontSize[5] = 20;
fontSize[6] = 24;

function changefontsize(whichNo)
{
document.getElementById('menu').style.fontSize=fontSize[whichNo];
}
</script>

<body id="menu">
<a href="javascript:changefontsize(2);">12</a>
<a href="javascript:changefontsize(3);">14</a>
<a href="javascript:changefontsize(4);">16</a>
<a href="javascript:changefontsize(5);">20</a>
<a href="javascript:changefontsize(6);">24</a>
</body>
 
Okay, as default (i.e. no scripts support) you could set the links to go to the page with different font sizes (graceful :D), then with JavaScript set the elements' onclick attributes?
 
C'mon, you might think it's useless, but it's always good to practise these things! :D

Code:
function changefontsize(whichNo)
{
document.getElementById('menu').style.fontSize=fontSize[whichNo];
}

Try adding the units to the end of that - e.g. fontSize[whichNo]+'em'; (or +'px');
 
Back
Top Bottom