Image Size Javascript [closed]

-1

Good evening guys, I'm having a javascript problem that is as follows:

I need to create div dynamically in a for and put these divs in an image, I could do this with the following code:

for(y = 0;y<z;y++){
         passarImagem[y] = document.createElement("div");

         var testando = document.createElement("img");
         testando = "<img src=exemmplo.png>";
         testando.width = 500;
          testando.height = 500;

         passarImagem[y].innerHTML = testando.src;
     }

I need to scale these images to a specific size, I put 500 as an example, but this way I did not work, I would like to know if you have a way to change the size of this image.

    
asked by anonymous 03.11.2018 / 22:55

1 answer

3

Here is an example using appendChild() , which is nothing more than creating a "child" for a "parent", where each <img> element is a child and the parent div is the parent:

for(y = 0; y < 10; y++){
  principal = document.getElementById("principal");
  
  var imagem = document.createElement("img");
  
  imagem.src = "https://i.imgur.com/F543MoZ.png";
  imagem.width = 30;
  imagem.height = 30;

  principal.appendChild(imagem);
}
<div id="principal"></div>
    
03.11.2018 / 23:23