+ 2

How to change image source using JavaScript?

I Need to change image source using JavaScript for example HTML <img id="picture" src="http://someurl.com" width="300" height="300" /> JS var file = document.getElementById("picture") //now goes something that i dont understand file.src = "otherURL" I think that everything in this JS is incorrect . Can you tell me how to change source in JS?

11th Jun 2018, 7:56 AM
ivankoshan
ivankoshan - avatar
2 odpowiedzi
+ 5
ivankoshan First of all, you can't include a picture from your device on sololearn. The source of the image should be online means it should be uploaded somewhere else on the net not on your device. If you want to change your image with js. You can see the small code I have made for you. Feel free to copy. https://code.sololearn.com/W1MnrlgPuubq/#html
11th Jun 2018, 8:26 AM
Akash Pal
Akash Pal - avatar
+ 3
you cannot change an images source like that. you can only assign the image to a different/another source.
11th Jun 2018, 7:58 AM
᠌᠌Code X
᠌᠌Code X - avatar