The image() Object

The subject of creating an image on the fly seems to have at least a couple of approaches. An image <img> element can be created or an image() object constructed.

Images are an important part of a webpage and it is normal to hard-code them in the pages. However, in the case of a slideshow or presentation the image files can be quite large and it doesn't make sense to pre-load them all when the page is created.

In my example I will create an image object from an array and attempt to replace that image with another from the same array.

I am not sure I like the method of deleting - what happens to the first image object?

Image will appear here
Top

Links

Link to PDF Disabled

If you require a copy please email tempusfugit.me.uk

Top

References -

  • 1 - HTML DOM Image Object - https:// www.w3schools.com/jsref/ dom_obj_image.asp
  • 2 - Button to create an IMG elementB - https:// www.w3schools.com/ jsref/tryit.asp? filename=tryjsref_img_create
  • 3 - HTMLImageElement: Image() constructor - https:// developer.mozilla.org/ en-US/docs/Web/API/ HTMLImageElement/Image
  • 4 - HTML DOM Element removeChild() - https:// www.w3schools.com/jsref/ met_node_removechild.asp