When I\'m adding a div to body, it\'s returning the body as the object and then whenever I use that - it\'s obviously using body. Bad.
Code:-
var hol
jQuery methods returns the set they were applied on.
Use .appendTo:
var $div = $('<div />').appendTo('body');
$div.attr('id', 'holdy');
Using jQuery appendTo try this:
var holdyDiv = $('<div></div>').attr('id', 'holdy');
holdyDiv.appendTo('body');
var $div = $('<div />').appendTo('body');
$div.attr('id', 'holdy');
$('</div>').attr('id', 'holdy').appendTo('body');
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)
$('body').append($('<div/>', {
id: 'holdy'
}));