Clear html from comments using javascript

Clear html from comments using javascript

Remove comments

To clear your html code from comments using javascript, just open your browser console on the page you'd like to clear and execute the code:

document.querySelector('html').outerHTML.replace(/<!--[\s\S]*?-->/g, '');

In the output you'll get the html code of the page without any comments (so all the comments like <!--wp code prettify--> or <!-- #comment-## --> will be removed).

Remove multiple elements

If you need to remove multiple elements from the page it can be done in the same way - by executing:

document.querySelectorAll('[class*="reply-"]').forEach((element) => {
    element.remove();
});

So all elements with class containing reply- will be deleted from the page.

Combined script to remove elements

Also you can run those operations as oneliner in the browser console:

document.querySelector('#respond').remove(); document.querySelectorAll('[class*="reply-"]').forEach((element) => {
        element.remove();
    }); document.querySelector('#comment-wrap').outerHTML.replace(/<!--[\s\S]*?-->/g, '');