tags:

views:

50

answers:

2

is the following writing images? If so, where is it placing it in the DOM?

for(var j = 0; j < portfolio_itemList[i-1].url.length; j++) { 
            $('<img>').attr('src', portfolio_itemList[i-1].url[j]);
        }

Don't you need to specify a function to tell it to write the image? I am just trying to figure out what that line is doing in the for loop.

A: 

You're going to want to append that image you create to somewhere on the document

for(var j = 0; j < portfolio_itemList[i-1].url.length; j++) { 
    $('<img>').attr('src', portfolio_itemList[i-1].url[j])
        .appendTo("#someTargetSelector");
}
Hugoware
+2  A: 

That code forces the browser to preload images without needing to insert it in the DOM. It looks like it's intentionally not displaying it to the user, just shoving files in the browser's cache. That way, when the user views them later, they load basically instantly.

ojrac
so anything done like this without a function is done via preload?
CoffeeAddict
Well, if the code doesn't call some function like appendTo [see HBoss' answer] or at least saving a reference to the <img>, it can't accomplish anything other than preloading the images.
ojrac