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

omg picture omg · Sep 6, 2009 · Viewed 81.6k times · Source

I tried the following:

$.load("Views/chatBox.html").appendTo('body')

Console Output:

TypeError: $.load is not a function 

EDIT: The answer should only be one line of code; that's enough, I think.

Answer

Rob Evans picture Rob Evans · Feb 1, 2011

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'
});