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 holdyDiv = $('body').append('div');
$(holdyDiv).attr('id', 'holdy');
The 'id' of holdy is now being added to body... eh? What am I doing wrong.
Instead use use
appendTo
.append
orappendTo
returns a jQuery object so you don't have to wrap it inside$()
..appendTo()
reference: http://api.jquery.com/appendTo/Alernatively you can try this also.
Using jQuery appendTo try this:
jQuery methods returns the set they were applied on.
Use .appendTo: