title: Select all img tags and give them a src
body: <p>I've tried a lot of ways to fix this problem but can't figure it out.</p>
  
  <p>My problem is that i try to select all <code>&lt;img&gt;</code> by doing </p>
  
  <pre><code>document.getElementsByTagName("img")
  </code></pre>
  
  <p>and then add <code>.src=text[x]</code> to it like this:</p>
  
  <pre><code>document.getElementsByTagName("img").src=text[x];
  </code></pre>
  
  <p>Well that doesn't work. I've also tried to use this: </p>
  
  <pre><code>var r = document.getElementsByTagName("img");
  r.src=text[x];
  </code></pre>
  
  <p>Again, nothing. If i use this code(<code>immg</code> is the ID all the <code>&lt;img&gt;</code> have): </p>
  
  <pre><code>document.getElementById('immg').src=text[x];
  </code></pre>
  
  <p>It does work but only on the first object since it's only searching for one element with ID <code>immg</code> and not all of them.</p>
  
  <p>My full code:</p>
  
  <p>first function</p>
  
  <pre><code>function generateChar()
  {
      var text = [
          "img/Water1.png",
          "img/Water2.png",
          "img/Water3.png",
          "img/Water4.png",
          "img/Water5.png",
          "img/Water6.png",
      ];
      var size = text.length;
      var x = Math.floor(size*Math.random());
      //document.getElementsByTagName("img").src=text[x];
      //document.getElementById('immg').src=text[x];
      var r = document.getElementsByTagName("img");
  
      r.src=text[x];
      //console.log(r);
  }
  </code></pre>
  
  <p>the other usefull code:</p>
  
  <pre><code>var nbDiv = 50;
  for(var i = 0; i &lt; nbDiv; i++){
      var div = document.createElement('div');
      var imgg = document.createElement('img');
  
      div.id = "d"+i ;
      imgg.id = "immg";
      imgg.className = "iimg";
      div.className = "movement timeSpan";
      document.querySelector('body').appendChild(div);
      div.appendChild(imgg);
  }
  </code></pre>
  
  <p>and <code>generateChar()</code> is called under the for()</p>
  
  <p>So what i would want to achive is giving all the img a random picture(wich works i only need to select the right items).</p>
  
  <p>All solutions are welcome.</p>