Instead use use appendTo
. append
or appendTo
returns a jQuery object so you don't have to wrap it inside $()
.
var holdyDiv = $('<div />').appendTo('body');
holdyDiv.attr('id', 'holdy');
.appendTo()
reference: http://api.jquery.com/appendTo/
Alernatively you can try this also.
$('<div />', { id: 'holdy' }).appendTo('body');
^
(Here you can specify any attribute/value pair you want)