When dynamically creating DOM objects in jquery is it better to use pure string concatenation or should I use the jquery methods? Which is the more “jQuery way”?
var tr = $('<tr/>').addClass('foobar');
// or $('<tr class="foobar"/>');
tr.append('<td>' + someobj.property + '</td>');
// or ...
tr.append($('<td/>').text(someobj.property));
From what I understand it is faster to create objects using just strings but sometimes it is just more convenient to use the helper methods. In general, I try to use string concatenation whenever possible since it cuts down on the overhead, but sometimes it just makes more sense to use the jQuery builder methods.