JSFiddle - React, Tailwind, and code Playground

HTML

<div class="welcome-msg">
    <!--Comment --><span>hello <!--Another comment--></span> world
</div>

JavaScript

$.fn.removeComments = function() {
    this.contents().filter(function() {
        return this.nodeType == 8;  
    }).remove();
    
    this.children().each(function() {
       $(this).removeComments(); 
    });
    
    return this;
};


console.log($(".welcome-msg").clone().removeComments().html());