Skip to content

Instantly share code, notes, and snippets.

Created December 19, 2022 16:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Load or Nest Content From Another Page
// See an text example of this here:
window.addEventListener("load", (event) => {
.then(function (response) {
return response.text();
.then(function (html) {
// Convert the HTML string into a document object
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
// Get a specific element in the HTML
var element = doc.querySelector("#load-source");
// Add element to current page
document.getElementById("load-destination").innerHTML = element.innerHTML;
.catch(function (err) {
// There was an error
console.warn("Fetched html error", err);
$(function() {
$('#load-destination').load(" #load-source");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment