As Brunorb said, you probably won’t be able to do what you want using only HTML/Javascript. But if your page . html is on your server and you have access, you could change it using javascript only, but it wouldn’t be the user’s browser engine, it would be through Node.JS, which is Chrome’s Engine V8 running on the server.
If you want to change the source code of a page, you basically have two alternatives, or change it on the server, before sending as response to the client (in this case you could use Nodejs), or you dynamically change the client using Javascript, which is actually not a real change in the source code but only a manipulation of the document in the client.
You could also do something complex, like create a copy of the file. html in the client’s Storage using Fileapi with another series of processes that would get more or less the result you expect, but I think that’s not quite what you want.
https://scotch.io/tutorials/use-the-html5-file-api-to-work-with-files-locally-in-the-browser
Finally, the javascript code that you run in the client’s browser does not have direct access to your files on the server, that is, you could not use only it to modify your source code. But there are ways to get this result, modify the source code of a web page with javascript, but this involves more technologies than just HTML/Javascript running in the browser.
Managed to solve?
– durtto