The code is as follows :
<html>
<head>
<title>JS Test</title>
<script>
var con=document.getElementById("con");
function btn()
{
con.innerHTML="Hello";
}
</script>
</head>
<body>
<input type="button" value="Click me" onclick="btn()" />
<div id="con"></div>
</body>
</html>
I'm not getting the required result. Any one please explain why ? But I'm getting the result when con is initialized inside the function ie.
function btn()
{
con=document.getElementById("con");
con.innerHTML="Hello";
}
How to access the global variable declare outside the function? Also tried window.con , but not works.. please explain the reason...