Skip to content
Advertisement

I have created image tag in JavaScript, but it is not displaying image on web page

I am calling this function on add button from my PHTML. On click of add button I want to show image of selected fruit in <div>.

JavaScript

In this code I have created <img> tag and passing image path to src, to show selected image on web page. It is correctly taking path of images but it is not appending <img> tag and not displaying image on web page.

Advertisement

Answer

Your problem is, most likely, in this line:

JavaScript

This creates an element, assigns the src property to it and then assigns the value of this src property to variable img1. Instead, you should do this in two lines:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement