I am using the code below that loops around thousands of time, I need this to be as fast as possible, however I am not an expert in Javascript and all I know is that this code is faster than doing it with the innerHTML
method.
Can it be optimized? If so, how?
var a,b,c,d,e,
trEl, tdEl, imgEl
for (i = 0; i < docs.length; i++) {
trEl = document.createElement('tr');
tdEl = document.createElement('td');
td1El = document.createElement('td');
td2El = document.createElement('td');
td3El = document.createElement('td');
imgEl = document.createElement('img');
var str
a = docs[i]['a']
b = docs[i]['b']
c = docs[i]['c']
d = docs[i]['date'] + " - " + docs[i]['timestamp']
e = docs[i]['_e']
trEl.setAttribute('id', e);
trEl.setAttribute('ondblclick', 'scan(' + '"' + e + '"' + ')');
imgEl.setAttribute('src', 'css/bullet.png');
tdEl.appendChild(imgEl);
tdEl.appendChild(document.createTextNode(a));
td1El.appendChild(document.createTextNode(d));
td2El.appendChild(document.createTextNode(b));
td3El.appendChild(document.createTextNode(c));
trEl.appendChild(tdEl);
trEl.appendChild(td1El);
trEl.appendChild(td2El);
trEl.appendChild(td3El);
document.getElementById("search-results").appendChild(trEl)
}