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
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.
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.
The jQuery append() method inserts content AT THE END of the selected HTML elements.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With