I have a div in which I am dynamically adding an image.
div.append('<img class="prod48" src="' + url + '" />');
Now the url is set by focusout of a textbox depending on the text in it. Since the append function will go on appending, how should I just change this url and not append another image in the div? The first time the focusout is called only then should I be able to append and rest times updating the url.
If you want to update the image element after it has been added to the document, you’ll have to have some way of referencing it.
A couple of ideas come to mind immediately:
Give the image a unique ID, and then use that:
Alternately, construct the image dynamically the first time, and keep the element in a variable: