tags:

views:

35

answers:

3

I saw in the documentation that .append allows you to add things to an element. But I want to end a div right before the </body> tag

+4  A: 
$('body').append('<div />');
Ninja Dude
+2  A: 

Wait, so why doesn't this work?

$("body").append('<div id="your_div" />');
tjko
didn't know the body was an attribute. =)
DerNalia
@DerNalia `body` is a `tag` and not an attribute... :)
Reigel
@DerNalia `body` is not an attribute. In jQuery, it is a `selector`
Ninja Dude
Both correct. @DerNalia, you can use HTML tags, CSS selectors, and more as selectors in jQuery. Find out more on the doc pages of the selector engine jQuery uses, Sizzle (http://wiki.github.com/jeresig/sizzle/).
tjko
A: 

You can use this:

$('body').append('<div>footer</div>');

but also this:

$('<div>footer</div>').appendTo('body');

or this:

$('body').html($('body').html()+'<div>footer</div>');

Reference with differences here: http://api.jquery.com/appendTo/

s3m3n