title: does this need to be done with eventlistener instead?
body: <p>I am trying to append my selections to an array when I click my submit button. I am assuming I need to be using eventlistener onclick function for this instead.</p>
  <p>With my current method it is throwing the following error...</p>
  <p><strong>EDITED</strong>
  <em><strong>Cannot read properties of null (reading 'length') at submit_button.onclick</strong></em></p>
  <p>Here is what I have currently, can anyone advise where I am going wrong please...</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var container = document.getElementById('my_dataviz');
  var array = ["One", "Two", "Three", "Four", "Five", "Six",
    "Seven", "Eight", "Nine", "Ten"]
  
  let identifier = 0;
  let SelectCount = 0;
  
  array.forEach(element =&gt; {
    const button = document.createElement("button");
    button.className = "btn";
    button.id = element;
    button.value = element;
    button.type = "button";
    const text = document.createTextNode(element);
    button.appendChild(text);
    container.appendChild(button);
  });
  
  let btn = document.getElementsByClassName("btn");
  
  for (let i = 0; i &lt; btn.length; i++) {
    (function(index) {
      btn[index].addEventListener("click", function() {
        console.log("Clicked Button: " + index);
  
        let isPresent = false;
  
        this.classList.forEach(function(e, i) {
          if (e == "button-focus") {
            isPresent = true;
          } else {
            isPresent = false;
          }
        });
  
        if (isPresent) {
          this.classList.remove("button-focus");
  
          SelectCount -= 1;
          document.querySelectorAll('.btn').forEach(item =&gt; {
            if (!item.classList.value.includes('button-focus')) item.disabled = false
          })
  
        } else {
          this.classList.add("button-focus");
  
          SelectCount += 1;
          if (SelectCount &gt; 2) {
            document.querySelectorAll('.btn').forEach(item =&gt; {
              if (!item.classList.value.includes('button-focus')) item.disabled = true
            })
          }
        }
      })
    })(i)
  }
  
  
  const dataResults = []
  
  let results = document.getElementsByClassName('.btn.button-focus')
  let submit_button = document.querySelector('modal-btn')
  
  submit_button.onclick = function() {
    for (let i = 0; i &lt; results.length; ++i) {
      dataResults.push(results)
      console.log(results)
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.my_dataviz {
    width: auto;
    height: auto;
    margin-top: 15px;
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: space-evenly;
  }
  
  .my_dataviz button {
    font-family: "walkway";
    font-size: 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    width: 130px;
    height: 25px;
    background-color: Transparent;
    -webkit-tap-highlight-color: transparent;
    background-repeat: no-repeat;
    border: none;
    letter-spacing: 1.6px;
    margin: 10px;
    border: 1px solid transparent;
  }
  
  .my_dataviz button:hover {
    box-sizing: border-box;
    background-color: var(--primary_orange);
    color: var(--dark);
    font-weight: bold;
    border: 1px solid #000;
    border-radius: 5px;
    cursor: pointer;
    /*box-shadow: var(--shadow);*/
  }
  
  .btn.button-focus {
    background-color: var(--primary_orange);
    color: var(--dark);
    font-weight: bold;
    border: 1px solid #000;
    border-radius: 5px;
  }
  
  .modal-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    height: 50px;
    align-items: center;
    text-align: center;
    background: var(--primary_med);
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
  }
  
  .modal-footer .modal-btn {
    font-family: "walkway";
    font-size: 16px;
    font-weight: bold;
    width: 100px;
    height: 28px;
    border-radius: 5px;
    align-items: center;
    letter-spacing: 1.6px;
    box-shadow: var(--shadow);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="my_dataviz" id="my_dataviz"&gt;
  
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
    &lt;input class="modal-btn" type="button" value="Select it" /&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>