Change the <img /> image using a JavaScript Image object
I have a JavaScript Image Object that I dynamically load using jQuery.
What I want to do is change the image <img /> with the Image stored on my object. How can I do it?
Note. I want to avoid changing the source of the <img /> , since it downloads it again from the server, and I already have the image stored in the image object
+6
4 answers
Make your new image in javascript memory, and then add it after the original image, then delete the original. You can also cache the original before deleting it if you want to reuse it.
HTML
<img id="replace" /> Js
var img = new Image(); img.src = "someUri.png"; $("#replace").after(img); $("#replace").remove(); 0