There is an array of images:

var slide = new Array(); slide[0] = new Image(); slide[0].src = "photo0"; slide[1] = new Image(); slide[1].src = "photo1"; 

And so I tried to display it on the page:

  <img name="myImg"> document.images["myImg"].src = slide[0].src; 

But it shows a white square, torn in the middle. Tell me, please, what is wrong?

  • Do you understand what you write yourself? You know what new Image(); means new Image(); eg? Or, for example, tell me why the presence of the string photo0 in the src attribute should display a picture? - Alexey Shimansky
  • @ Alexey Shimansky, about new Image () - as I understand it, it's almost like with files in Php. The variable is assigned this new Image (), perhaps with a width and height, and then a picture is added in the form of var photo.src = "Here is path". But the fact of the matter is that I cannot understand how to show it in any way. That's why I asked a question - Bipa
  • Переменной присваивается это new Image(), - what exactly happens when new Image() you do not know? because judging by the record document.images["myImg"].src = slide[0].src; definitely don't know. Although somewhere read about new Image () ........ а потом в виде var photo.src = "Here is path" добавляется картинка. - Nuuuu let's say ... well, and where does your photo0 ? - Alexey Shimansky
  • @ Alexey Shimansky, Image () is a designer, as I know. But yes, you are right, I don’t really know how to use it - Bipa
  • new Image() creates a new DOM element. If specifically, the picture. If you embed this construct in the console, you will see <img> . Hence the first step and the question: in the end, do you want to insert the path to the image into the already created <img name="myImg"> element? then manipulations with new Image () are unnecessary ........... or still create dynamically? then <img name="myImg"> absolutely not needed here - Alexey Shimansky

0