I am working on embedded WKWebView (a browser view on iOS), so I don't want/can't use any libraries and need to achieve the following purely in JavaScript.
While content of the web view is loading, I want to clear previous content, and display something like "Loading...".
The most obvious way is to
document.body.innerHTML = "Loading...";
(method 1)
But the problem is it leaves other elements (e.g. scripts, styles) of the page intact, while I need the style to be reset (e.g. clear background, fonts, etc)
There is a way to clear everything by removing HTML element, which is good
document.documentElement.remove()
(method 2)
But how can I then add a new HTML element with new content?
So is there a way to add a new HTML element using method 2, or to clear style, scripts, etc using method 1?
Note: Loading...
is just an example text I want to use, actual content could be proper HTML if it's important.