DEV Community

Discussion on: how do i add pictures in javascript

Collapse
 
prakhart111 profile image
Prakhar Tandon

You can use document.createElement() method to create an an empty img element, then add the source.

function img_add() {
            var img = document.createElement('img');
            img.src = #    //link to image
            document.getElementById('body').appendChild(img);
}
Enter fullscreen mode Exit fullscreen mode

I think that's what you were looking for, right?

Collapse
 
azloop profile image
Austin

yes thank you

Collapse
 
curiousdev profile image
CuriousDev

If you want to load an image into the page, this looks fine. If you do not want to load it into the DOM, then you should be able to do a simple HTTP request to get the image.
Can you please describe the issue more, @looph8le ?

Collapse
 
azloop profile image
Austin

i dont know how to add pictures to javascript