user3407899 user3407899 - 1 year ago 56
HTML Question

jQuery dynamically load image not working showing multipule images how to I replace the src= and not append to it

Okay so I have the little function below on my html page that receives data from another script using to update the url.

The problems is the image can change up to 10 times during the user is using my page.

If I am loading one image, it works, but multiple images don't work, as it appends the next picture to the


And not replace it so I end up with multiple images in my div.

How do I changed it so it replace the
and not append to it?

is originally empty

Here's my jQuery script:

<script src="/js/jquery.js"></script>

function hellou(url){

var img = document.createElement("img");
img.src = url;

var src = document.getElementById("cpt_img");

Can someone show me an example to fix this?

Answer Source

use jquery>>

function hellou(url){



can I have your HTML .. so that I can give you more specific answer