getElementById() returns null even though the element exists

getelementbyid, html, javascript, null

Solution

You have to put this in a `document` `load` event. The DOM hasn't gotten to `abc` by the time the script is executed.

Problem

I'm trying to get the element with getElementById(), but it returns null even though the element exists. What am I doing wrong? ``` <html> <head> <title>blah</title> <script type="text/javascript"> alert(document.getElementById("abc")); </script> </head> <body> <div id="abc"> </div> </body> ```

Original source

Related problems