What would be the native javascript equivalent to the jquery below?
$('#anyDiv').load("anyPage.htm");
What would be the native javascript equivalent to the jquery below?
$('#anyDiv').load("anyPage.htm");
Yes, there is:
function load(target, url) {
var r = new XMLHttpRequest();
r.open("GET", url, true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
target.innerHTML = r.responseText;
};
r.send();
}
load(document.getElementById('anyDiv'), 'anyPage.htm');
You can try this,
window.onload = () => {
fetch('/path/to/page.html')
.then(data => {
return data.text()
})
.then( data => {
document.getElementById("parentContainer").innerHTML = data;
})
}
You can try like this.
document.getElementById("anyDiv").innerHTML='<object type="text/html" data="anyPage.html" ></object>';