There is always append () .
$('#container').append('<span>foobar baz</span>');
It seems to me that just using string concatenation and append would be the least complicated and probably the fastest option. However, the following unverified example of a method (possibly) simplifies the creation of elements and allows you to add them to this parent element:
function elemCreate(type, content, attrs) { elem = '<' + type + '></' + type + '>' e = $(elem).attr(attrs) e.append(content) return e } stuff = []; stuff.push(elemCreate('a', 'Click me!', {'href': 'http://stackoverflow.com'}); $(stuff).appendTo($('#container'));
vezult
source share