Skip to content

Instantly share code, notes, and snippets.

@sakunyo
Created March 22, 2012 03:07
Show Gist options
  • Save sakunyo/2155359 to your computer and use it in GitHub Desktop.
Save sakunyo/2155359 to your computer and use it in GitHub Desktop.
loop
var foo = [
{ "id": 1, "alt": "Orange" },
{ "id": 2, "alt": "Apple" },
{ "id": 3, "alt": "Banana" }
],
item,
html;
for ( var i = 0, len = foo.length; i < len ; i++ ) {
item = foo[i];
if ( i % 5 === 0 && i !== 0 ) {
html += '</div></li>' + "\n";
}
if ( i % 5 === 0 ) {
html += '<li><div>' + "\n";
}
html += '<div class="box"><img src="item'+ item.id +'.png" alt="'+ item.alt +'" /></div>' + "\n";
}
html += '</div></li>' + "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment