title: Using a JavaScript variable to link an image in a image tag in HTML with DOM
body: <p>I want to use a JavaScript variable which is equal to the url of an image in a html img tag. I need the following tag to be able to display the image that is tied to the variable.</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>document.getElementById("id-of-img-tag").src = imgVar;
  
  document.getElementById("id-of-img-tag").innerHTML = imgVar;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;img id="id-of-img-tag" src=" " alt="img"&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Both of the lines of JS result with the alternative being displayed for the img tag "img".</p>