title: TypeError: document.getElementById(...) is null Django + JS
body: <p>I'm having an error while executing the following code:</p>
  
  <pre><code>var toppings = ['Zucchini', 'Fresh Garlic', 'Black Olives', 'Anchovies',
    'Barbecue Chicken', 'Artichoke', 'Spinach', 'Ham', 'Sausage', 'Mushrooms'];
  
  var appended = 0;
  var maxAppended = 3;
  
  document.getElementById('add').onclick = () =&gt; {
    appended+=1;
    if(appended &lt;= maxAppended){
    const topping = document.createElement('select', {
      'name': 'Topping',
      'class': 'form-control'
    });
    list.appendChild(topping);
    toppings.forEach(function(item, i, arr) {
      const ch_topping = document.createElement('option');
      ch_topping.innerHTML += item;
      topping.appendChild(ch_topping);
    });
    }
    else {
        alert('You should stop');
    }
  };
  </code></pre>
  
  <p><strong>page1.html:</strong></p>
  
  <pre><code> &lt;div class="form-group" id='add_one'&gt;
      &lt;br&gt;
      &lt;h5&gt;You can add up to 3 toppings to your pizza!&lt;/h5&gt;
      &lt;ol id="list"&gt;&lt;/ol&gt;
      &lt;button class="btn btn-primary" id="add" type="submit"&gt;Add topping&lt;/button&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>This code fails with the following error:</p>
  
  <pre><code>TypeError: document.getElementById(...) is null
  </code></pre>
  
  <p>I'm including JavaScript on my <strong>base.html</strong> file and <strong>page1.html</strong> extends this file.</p>
  
  <p>My <strong>base.html</strong> <code>&lt;head&gt;</code>:</p>
  
  <pre><code>&lt;title&gt;{% block title %}{% endblock %}&lt;/title&gt;
      &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous"&gt;
      &lt;script src="{% static 'js/main.js' %}"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><code>window.onload()</code> didn't help</p>
  
  <p><code>jQuery's $(document).ready(</code>) didn't help</p>