document.getElementById() doesn't work?

Viewed 42411

No much to say,

<html>
    <body>
        <script>
            var x = document.getElementById('btn1');
            alert(x);
        </script>
            <input type="button" id="btn1" value="Clickme" onclick="alert('1')" />
    </body>
</html>

The alert message is null instead of a message contain details of the object or something like that.

What is the problem?

7 Answers
Related