OK, I’m new at JavaScript, but I’m trying to change the innerHTML of a div element.
Here is my script that is not working:
<head>
<script type="text/javascript">
function var1() {
document.getElementById('test').innerHTML = 'hi';
}
window.onLoad = var1();
</script>
</head>
<body>
<div id="test">change</div>
</body>
It should work, but for some reason it does not, any help?
Rather than assigning
var1towindow.onload, you’re currently calling the function and storing its result. Also, this might be obvious, butvar1seems like an odd name for a function. Try this:Note the casing of
onload, as well as the missing parentheses aftervar1.