I recently started learning about web development, in particular Javascript, and I'm trying to write some simple functions to advance my grasp of the language. I wrote a function to resize a box's height to be proportional to the window, but for some reason it isn't working - the resize function is not updating the page each time I resize the browser window. I feel like I'm making some really silly error, but because I'm not familiar with Javascript I can't figure out what it is.
My HTML is extremely simple:
<body>
<div id = "box">Hi.</div>
</body>
and the Javascript code is:
function resizeToScreen(element, percent)
{
var wHeight = window.innerHeight;
var objHeight = wHeight * (percent/100);
element.style.height = objHeight +"px";
}
window.onresize = resizeToScreen(document.getElementById('box'), 50);
Here's the link to the jsFiddle, which highlights the box yellow: http://jsfiddle.net/sallyg/mb8hB/1/