First, it's important to note that append
ing is a much more computationally expensive operation than setting innerHTML
on an element. Second, it's important to note that jQuery parses HTML strings (e.g. $('');
) into DOM elements via document.createElement
. In other words, it's not like concatenating a string; you cannot create partial elements.
What you want is to build an HTML string with raw string concatenation, then dump that into the DOM via innerHTML
. For example:
var colHTML = [];
var numPerCol = Math.ceil(response.length/3);
var i=0;
$.each(response, function(key, value) {
var curCol = Math.floor(i / numPerCol);
if (i % numPerCol == 0)
colHTML[curCol] = '';
colHTML[curCol] += '' + value.nombre + ''; // if nombre has invalid HTML, you need to escape it
});
var html = '';
document.getElementById('mylist').innerHTML = html;