Target whole page – NOT RECOMDNDED
window.addEventListener('load', function()
{
document.body.innerHTML = document.body.innerHTML.replaceAll(
"REPLACE_THIS_TAG",
"Replace with this"
);
});
WARNING!!!!!! – This rewrites the entire <body>, the browser destroys the old DOM nodes and creates new ones. If you’ve already done things that like attach click handlers they won’t work!
Target a section of the page only – BETTER APPRAOCH
Better approach, target just a specific section of the page, e.g. within a specific <div> ID:
window.addEventListener('load', function()
{
const MyContainerId = document.getElementById('MyContainerId');
if(MyContainerId)
{
MyContainerId.innerHTML = MyContainerId.innerHTML.replaceAll(
"REPLACE_THIS_TAG",
"Replace with this"
);
}
});
