title: Trying to use Javascript array to display Random images in <div>
body: <p>I'm not well know about javascripts, got this code from a website.
  Using javascript to display random images from array in div
  javascript working fine.
  <strong>But loaded images displays in random sizes</strong>
  <strong>tried using css style and all css html image attributes to resize them but nothing works, as they are displayed directly through javascript</strong></p>
  
  <p>want something to resize them directly in javascript</p>
  
  <p>code main :</p>
  
  <pre><code>&lt;script&gt;    
             var arrayImg = new Array();
             arrayImg[0] = "a11.jpg";
             arrayImg[1] = "a12.jpg";
  
  
              getRandomImage(arrayImg, "");
  
            function getRandomImage(imgAr, path) {      
              path = path || 'images/'; // default path here
              var num = Math.floor( Math.random() * imgAr.length );
              var img = imgAr[ num ];
              var imgStr = '&lt;img src="' + path + img + alt = "" &gt;';
              document.writein(imgStr); 
              document.close();
              }
  
           &lt;/script&gt; 
  </code></pre>
  
  <p>code I used to resize image : <strong>(but didn't work)</strong> :</p>
  
  <pre><code>&lt;script&gt;    
             var arrayImg = new Array();
             arrayImg[0] = "a11.jpg";
             arrayImg[1] = "a12.jpg";
  
  
              getRandomImage(arrayImg, "");
  
            function getRandomImage(imgAr, path) {      
              path = path || 'images/'; // default path here
              var num = Math.floor( Math.random() * imgAr.length );
              var img = imgAr[ num ];
              var img.height = 4vw;
              var img.width = 20%;
              var imgStr = '&lt;img src="' + path + img + img.height + img.width + alt = "" &gt;';
              document.writein(imgStr); 
              document.close();
              }
  
           &lt;/script&gt;  
  </code></pre>
  
  <p>even tried using : (but still didn't work)</p>
  
  <pre><code>document.writeln('&lt;td' + '&gt;&lt;imgstr"' + height="180" width="160" border="0" &gt;&lt;' + '/td&gt;');
  </code></pre>