I have a html5-document that contains this element:
<div id="imgContainer"></div>
The document loads, the user logs in, and some new text gets loaded and successfully displayed via Ajax (using jQuery). After a while (when the user makes a click) a new image should be inserted into the imgContainer-div.
I do this with this jQuery-command:
$("#imgContainer").html('<img src="newImage.png" alt="">');
The file newImage.png is located in the same directory as the html-file and the javaScript-file. But it does not appear in the browser-window. But it is correctly inserted into the source-code. I checked this with the developer-tools of my browser (safari). This tools don't report any error. But still the image is invisible. When I look into the list of resources I can see no newImage.png. Obviously the browser didn't load it. But why?
The image appears in the browser-window when I enter its URL. So the browser is able to load it. But it does not when I modify the html-document. Why?
Must I add some additional code to ma javaScript to tell the browser to load the image? If so: Can you tell me this code?
Edit:
try here: http://jsfiddle.net/YCs66/1/
<img>element is being injected into the page correctly? it is possible that your script executes before the container element loads, resulting the jQuery attempting to inject the image into an element that doesnt exist, is your code placed in a block that runs after DOM loads? here have a look, your code works fine in a fiddle: jsfiddle.net/TheBanana/LWpjr<img scr=??scrmeans nothing, it should besrcman. (referring to your jsfiddle)