I am trying to remove comments from HTML in Javascript but not working correctly. I need only plain HTML except comments
let sourceHTML = document.querySelector(".mySelector").innerHTML;
sourceHTML = sourceHTML.replace(/<--!(?:.|\n)*?-->/gm, '');
console.log(sourceHTML);
<div class="mySelector">
<!--Main content -->
<p>HTML content...</p>
</div>
Can anyone help me?