document.ready() and variable scope
Hi,
I don't yet understand some simple javascript / jquery basics:
- <head>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script>
var h = 11;
$(document).ready(function()
{
h = $(window).height();
alert(h);
});
</script>
</head>
<body>
<script>
alert(h);
</script>
First I get the alert h=11 and only after that the value from $(window).height(), meaning I don't have the value of that height() available in the scripts in the body;
What am I doing wrong?
Similar, using javascript only:
- <head>
<script>
var h;
function init()
{
h = 100;
alert(h);
}
</script>
</head>
<body onload=init()>
<script>
alert(h);
</script>
First I get the undefined, and then I get the 100.
Obviously there's something basic I don't yet understand.
Thanks.