If you are interjecting trusted html with jQuery.append() or jQuery.html() into "element1" and your css value of element2 be it div or span is floated left to fit element3 you will not be able to get offsetWidth , clientWidth , naturalWidth (google crome) of element3 with out a new event trigger.
var element1 = $('div.container');
while(i<=length){
var element2 = $('<span/>').attr({'id':''+[i]+'','class':'container'});
var element3 = $('<img/>').attr('src':''+source[i]+'','class':'img');
$(element1)children().remove();
$(element2).appendTo(element1).append(element3);
var elms = $(element3);
var chwidth = elms[i].offsetWidth // returns 0;
++i;
};
what you can do is return the context width of the elements before they're loaded.
while(i<=length){
$(element1).children().remove();
$(elemen2).appendTo(element1).append(element3);
var elms = $(element3);
var newelms = elms[i].load();
var chwidth = newelms[i]['context'].width // returns element3's contextual width
if(chwidth != 0) // make sure only the proper width is returned
var width = chwidth;
++i;
};
If this doesn't work then try:
while(i<=length){
$(element1).children().remove();
$(elemen2).appendTo(element1).append(element3);
var elms = $(element3);
var newelms = elms[i].load(function (){
//get the widths inside the load context
var width = this.width();
//pass the single width or el[i].width to next function
};
++i;
};