Solution 1 :

You can’t use image to change the image of an <img>. To do it you will need to use src.
Here is what you need below.

document.getElementById("task").src = "yoururl"

Solution 2 :

To change the image source, you can try the code below.

const img = document.querySelector("task");
img.setAttribute("src", "<url>");

setAttribute() will set the src attribute to your URL of your image.

Make sure to change <url> with your image URL!


You can also use the code below.

const img = document.querySelector("task");
img.src = "<url>";

Setting the source to your URL will correctly render the image.

Make sure to change <url> with your image URL!

Problem :

someone help please my image won’t load and I get a error

document.getElementById(“task”).image = “url”

I made sure the Id matches the id in html I don’t know what’s wrong

Comments

Comment posted by KammyCoder

still wont work :/

Comment posted by Michael Rogers

Do you mind showing me your console? And are you changing the “yoururl” to the path of which the image is?

Comment posted by KammyCoder

ohhhh wow ok I am stupid I am sorry it works now thank u

Comment posted by Michael Rogers

Glad I could help! Have a nice day and welcome to Stackoverflow!

Comment posted by KammyCoder

I got it to work already thank u

By