Quantcast
Channel:
Viewing all articles
Browse latest Browse all 60

Append content outside of loops – jQuery

$
0
0
//BAD
$.each(myArray, function(index, item) {
  var newTweet = '<li>' + item + '</li>';
  $('#statuses').append(newTweet);
});

//GOOD
var newTweet = '';

$.each(myArray, function(index, item) {
  newTweet += '<li>' + item + '</li>';
});

$('#statuses').html(newTweet);

Filed under: jQuery Tagged: jquery .html, jquery append

Viewing all articles
Browse latest Browse all 60

Trending Articles