Since you found the answer based on my help:
It seems that you are using jQuery. You can wrap the function call inside a ready function: Specify a function to execute when the DOM is fully loaded.
function loadImages(){
var img1 = "http://farm3.staticflickr.com/2826/11581275325_d61be12908_h.jpg"
var markup = "<h3>Images after pageload</h2>"+"<img src='"+img1+"' />";
$("#images").html(markup);
}
$( document ).ready(function() {
// Handler for .ready() called.
loadImages();
});
You may take a look at my codepan example