title: JavaScript set Image/Element source/attribute is not updating the Image/Element
body: <p>I'm trying to change the <code>src</code> attribute of an image each time a button is clicked, and when the last image appears, then it resets and displays the initial image.</p>
  
  <p>I get the <code>src</code> attribute of the image, and update it to new image, but the image does not change.</p>
  
  <pre><code>  var imgSrc = document.querySelector("#myImg").src;
    imgSrc = images[i]; /* Is not working */
  </code></pre>
  
  <p>Could you help me please? Thanks in advance.</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-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;&lt;/head&gt;
  
  &lt;body&gt;
  
    &lt;img width="60%" id="myImg" src="https://i.imgur.com/TiipKoJ.gif"/&gt;
    &lt;br&gt;&lt;br&gt;
    &lt;button onclick="changeImg ()"&gt;Change Image&lt;/button&gt;
  
    &lt;script&gt;
      var i = 0, images = ["https://i.imgur.com/TiipKoJ.gif", "https://i.imgur.com/QHOn5G9.gif", "https://i.imgur.com/wRbhXbc.gif", "https://i.imgur.com/wbegtAO.gif", "https://i.imgur.com/UIXLgFX.gif"];
  
      function changeImg() {
        var imgSrc = document.querySelector("#myImg").src;
  
        if (i &lt; 3) {
          i++;
          imgSrc = images[i];
        } else {
          i = 0;
          imgSrc = images[i];
        }
      }
    &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>