Sometimes, we want to append a div to the end of document with jQuery.
In this article, we’ll look at how to append a div to the end of document with jQuery.
How to append a div to the end of document with jQuery?
To append a div to the end of document with jQuery, we can call the append
method on the body element with a string with the div’s code as the argument.
For instance, we write:
$(document.body).append('<div>hello world</div>');
to select the body element with $(document.body)
.
Then we call append
with '<div>hello world</div>'
add the div as the last child of the body element.
As a result, we should see ‘hello world’ on the screen.
Conclusion
To append a div to the end of document with jQuery, we can call the append
method on the body element with a string with the div’s code as the argument.