You can’t remove anything from the source code using javascript.
You can only remove elements from the current rendered html of the page.
You need to save the file on the server after the edits, with a server script, to change the source.
If you are talking about changing the document source code, so that if I hit view source I don’t see the lines between your comment tags - it’s impossible using only javascript. As others have said you need to change the code server side so that only the part you want displayed gets sent to the client.
If you are talking about changing the rendered HTML so that the part between your comment tags is not displayed in a browser (but still visible in view source) then yes it’s possible.
If you are talking about changing the rendered HTML so that the part between your comment tags is not displayed in a browser (but still visible in view source) then yes it’s possible.
Using PHP to adjust the code before it’s handed to the browser is a much better way. Thank you for coming here though, and it’s great to see that you did find a successful solution.