title: Why does jQuery or a DOM method such as getElementById not find the element?
body: <p>What are the possible reasons for <code>document.getElementById</code>, <code>$(&quot;#id&quot;)</code> or any other DOM method / jQuery selector not finding the elements?</p>
  <p>Example problems include:</p>
  <ul>
  <li>jQuery silently failing to bind an event handler</li>
  <li>jQuery &quot;getter&quot; methods (<code>.val()</code>, <code>.html()</code>, <code>.text()</code>) returning <code>undefined</code></li>
  <li>A standard DOM method returning <code>null</code> resulting in any of several errors:</li>
  </ul>
  <blockquote>
  <p>Uncaught TypeError: Cannot set property '...' of null<br />
  Uncaught TypeError: Cannot set properties of null (setting '...')<br />
  Uncaught TypeError: Cannot read property '...' of null<br />
  Uncaught TypeError: Cannot read properties of null (reading '...')</p>
  </blockquote>
  <p>The most common forms are:</p>
  <blockquote>
  <p>Uncaught TypeError: Cannot set property 'onclick' of null<br />
  Uncaught TypeError: Cannot read property 'addEventListener' of null<br />
  Uncaught TypeError: Cannot read property 'style' of null</p>
  </blockquote>