tags:

views:

40

answers:

2
function changeSize( fontsize ) {

    var body = document.getElementById("body");
        var font = fontsize + "-font";
        body.className = font;

}


<input type="button" onclick="changeSize(small)" value="Small" /> 

Firefox console keeps saying that small is undefined. What am I doing wrong?

+5  A: 

You're passing in small as a variable, not a string to put into the DOM. Javascript is looking for the var small to be defined somewhere, and it's not. You need to pass in a string as an argument.

Try onclick="changeSize('small')"

Alex Mcp
+2  A: 

You are passing a variable named small to the function changeSize(), and Firefox is saying you have not defined a variable by that name yet. Though I suspect you really mean to pass the string "small". Put single quotes around it and you should be good.

<input type="button" onClick="changeSize('small')" value="Small" />
Timothy