title: Can't change id or src attributes inside a img tag using only Javascript
body: <p>I'm new with Javascript and, as expected, I'm in a hard time with it.
  I don't know what I'm doing wrong...
  Maybe my CDNs declarations are disorderly?
  I checked my js syntax many time, I just can't find the issue...
  Please, could someone help?</p>
  
  <p>Mission: change img src and id attribute (HTML5) using only Javascript.</p>
  
  <p>My HTML:</p>
  
  <pre><code>&lt;head&gt;
  &lt;!--CDN--&gt;
  &lt;script src="https://code.jquery.com/jquery-3.3.1.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" &gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"&gt;
  &lt;script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" &gt;&lt;/script&gt;
  &lt;script src="https://unpkg.com/tooltip.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
      window.onload = function imgChanger() {
          let bonanza = 0;
          let a;
          let b;
          try {
              a = document.getElementById("bla");
              bonanza = 1;
          } catch (error) {
              console.log("This elemente with id=bla doesn't exists.");
          }
          try {
              b = document.getElementById("ble");
              bonanza = 2;
          } catch (error) {
              console.log("This elemente with id=ble doesn't exists.");
          }
          if (bonanza == 1) {
              document.getElementById("bla").src = "CORRECT PATH TO IMG 01";
              document.getElementById("bla").id = "ble";
          }
          if (bonanza == 2) {
              document.getElementById("ble").src = "CORRECT PATH TO IMG 02";
              document.getElementById("ble").id = "bla";
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <p>.
  .
  .</p>
  
  <pre><code>&lt;body&gt;
      &lt;button id="xBtnOne" onclick="imgChanger()"&gt;
          &lt;img id="bla" src="CORRECT PATH TO IMG 01"&gt;&lt;/img&gt;
      &lt;/button&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>.
  .
  .</p>
  
  <p>Console error: Uncaught TypeError: Cannot set property 'src' of null at imgChanger.</p>
  
  <p>And,that freaking button does nothing but make me cry...</p>
  
  <p>Thanks for your time ppl...</p>