"TypeError: document.getElementById(...) is null" in JavaScript
<p>I have this tiny bit of code here, but it is not functioning when I reload the page, as I get the error</p>
<blockquote>
<p>TypeError: document.getElementById(...) is null</p>
<p>document.getElementById('devMode_checkbox').checked = false;</p>
</blockquote>
<p>The line(s) the error is referring to is as follows:</p>
<pre><code>checkDevMode();
        
        function checkDevMode() {

            var devModeIsTrue = getCookie('devModeIsTrue');
            if (devModeIsTrue === true) {
                
                document.getElementById('devMode_checkbox').checked = true;
                enableDevMode(devModeIsTrue);
                
            } else {
                
                document.getElementById('devMode_checkbox').checked = false;

            }
        }
</code></pre>
<p>I have quadruple checked the id of the element</p>
<pre><code>&lt;input type='checkbox' onchange='enableDevMode(this.checked)' id='devMode_checkbox'&gt;
</code></pre>
<p>and I don't really have a good understanding nor a solution for this problem. Also I could not find a working solution for this. (Sorry if this is a duplicate, but non of the given answers worked for me)</p>
<p>Is there a (proper) solution to this?</p>