i am writing a very simple application to get a element by id using javascript but it is returning null every time. I'm using chrome to test the application and unable to understand the cause. However, using the same id i'm able to do styling on it.
My Code:
<html>
<head>
<style>
body
{
padding-top: 10px;
}
#test
{
color:rgb(100,100,100);
}
</style>
<script>
var y = document.getElementById("test");
document.write(y.innerHTML);
</script>
</head>
<body>
<div>
<h3>History</h3>
<h1 id="test">Number of elements : </h1>
</div>
</body>
</html>
ErrorLog:
test.html:16 Uncaught TypeError: Cannot read property 'innerHTML' of null
at test.html:16
Please help...