JSFiddle - React, Tailwind, and code Playground
by Haze32
JavaScript
document.addEventListener("DOMContentLoaded", function () {
// URL of the other HTML page on the same domain
const targetPage =
"/intranet/PRAX/groups/bankruptcy/assets/Navigation/NavCode.html" // Change this to the correct path
// Fetch the HTML content of the target page
fetch(targetPage)
.then((response) => response.text())
.then((html) => {
// Create a temporary DOM parser
const parser = new DOMParser()
const doc = parser.parseFromString(html, "text/html")
// Find the nav element in the loaded page
const navElement = doc.querySelector("nav.restNav")
if (navElement) {
// Clone the element
const clonedNav = navElement.cloneNode(true)
// Find the target div where the nav should be appended
const targetDiv = document.querySelector("div#nav")
if (targetDiv) {
targetDiv.appendChild(clonedNav)
} else {
console.error("Target div#nav not found on the current page.")
}
} else {
console.error("Element 'nav.restNav' not found in the target page.")
}
})
.catch((error) => console.error("Error loading the target page:", error))
})