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.
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.
Add New HTML Contentappend() - Inserts content at the end of the selected elements. prepend() - Inserts content at the beginning of the selected elements. after() - Inserts content after the selected elements. before() - Inserts content before the selected elements.
HTML code can be appended to a div using the insertAdjacentHTML() method. However, you need to select an element inside the div to add the code. This method takes two parameters: The position (in the document) where you want to insert the code ('afterbegin', 'beforebegin', 'afterend', 'beforeend')
append( function ) A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert at the end of each element in the set of matched elements.
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... :)
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