How can jQuery load some html and append it to the <body> element?

An alternative solution:

jQuery('#AppendToMe').append( jQuery('<div>').load(...) );

This will append whatever you load into the #AppendToMe element.


Nope, all those answers are incorrect because they rely on having a separate container!

Do this:

$.ajax({
    url: "your.html",
    success: function (data) { $('body').append(data); },
    dataType: 'html'
});

I dont understand why placing container at the bottom of body and loading external page into that is not what you need?

What you can try is this:

<script type="text/javascript">
    $(function() {
        $("#container").load("Views/chatBox.html",function(){
            $(this).clone().appendTo("body").remove();
        });
    });
</script>

But im not 100% sure about this code... :)

Tags:

Jquery

Load