javascripthtmlgetelementbyid

Javascript: Does not change the div innerHTML


I really cannot understand why this does not work. I've tried couple of tricks but I just don't get it.

<html>
<head>
<script type="text/javascript">
alert('Hey');
    var vText = document.getElementById("results");
        vText.innerHTML = 'Changed';
        alert(vText.innerHTML);
</script>
</head>
<body>
<div id="results">
hey there
</div>
</body>
</html>

Solution

  • This is working as you can see here:

    http://jsfiddle.net/gHbss/

    It's important that you put the JavaScript after your HTML div container.