Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: how do I add a div to the end of my HTML file?

Tags:

jquery

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

like image 586
NullVoxPopuli Avatar asked Jul 28 '10 15:07

NullVoxPopuli


People also ask

How append HTML data to div in jQuery?

jQuery append() MethodThe append() method inserts specified content at the end of the selected elements. Tip: To insert content at the beginning of the selected elements, use the prepend() method.

How do I append after an element?

First, select the ul element by its id ( menu ) using the getElementById() method. Second, create a new list item using the createElement() method. Third, use the insertAfter () method to insert a list item element after the last list item element.

Which jQuery DOM method is used to insert content at the end of the selected elements?

The jQuery append() method inserts content AT THE END of the selected HTML elements.

How do I append a div after another div?

To append using the innerHTML attribute, first select the element (div) where you want to append the code. Then, add the code enclosed as strings using the += operator on innerHTML.


1 Answers

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/

like image 193
s3m3n Avatar answered Sep 28 '22 07:09

s3m3n