title: Change create table onclick Event to Onload Page
body: <p>Good night friends, i have this idea, and now i'm stuck trying to changing the code to onload().</p>
  <p>I tryied a lot of different ways, but no one worked for me.</p>
  <p>I'll let my code down here, if you can help me i apreciate, but show me how to do it, i don't wanna you just give me the finish code.</p>
  <p>HTML</p>
  <pre><code>&lt;div&gt;
      &lt;button&gt;Get&lt;/button&gt;
      &lt;div id=&quot;table&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>JS</p>
  <pre><code>let myTable = document.querySelector('#table');
  
  
  var distribuidores;
  fetch('http://localhost:3000/distribuidores')
      .then(res =&gt; res.json())
      .then(data =&gt; distribuidores = data)
      .then(() =&gt; console.log(distribuidores))
  
  let headers = ['id', 'codBrid', 'descricao']
  
  btnGet.addEventListener('click', () =&gt; {
      let table = document.createElement('table');
      let headerRow = document.createElement('tr');
  
      headers.forEach(headerText =&gt; {
          let header = document.createElement('th');
          let textNode = document.createTextNode(headerText);
          header.appendChild(textNode);
          headerRow.appendChild(header);
      });
  
      table.appendChild(headerRow);
  
      distribuidores.forEach(emp =&gt; {
          let row = document.createElement('tr');
          Object.values(emp).forEach(text =&gt; {
              let cell = document.createElement('td');
              let textNode = document.createTextNode(text);
              cell.appendChild(textNode);
              row.appendChild(cell);
          });
  
          table.appendChild(row);
      });
  
      myTable.appendChild(table);
  });
  </code></pre>
  <p>json</p>
  <pre><code>{
         &quot;distribuidores&quot;: [
          {
              &quot;id&quot;: &quot;1&quot;,
              &quot;codint&quot;: &quot;4613&quot;,
              &quot;descricao&quot;: &quot;HTMYS&quot;
          },
          {
              &quot;id&quot;: &quot;2&quot;,
              &quot;codint&quot;: &quot;10325&quot;,
              &quot;descricao&quot;: &quot;MPB LTDA&quot;
          }
      ]
  }
  </code></pre>