Insert HTML from a File into the DOM with jQuery
You may have a need to use jQuery to read HTML that you’ve stored in a file and then insert it into the DOM somewhere. Here’s how:
1. Create a file named myfile.html and add some simple HTML
2. In your .js file, include the following code:
if($('#myelement').length == 0) {
$.get("/" + window.location.pathname.split("/")[1] + "/files/custom/myfile.html", function(data) {
$(document.body).append(data);
});
}