JSFiddle - React, Tailwind, and code Playground
HTML
<div class="message">
<span>Menu 1</span><span>Menu 2</span>
</div>
CSS
.message span {
border: 1px solid red;
display: inline-block;
}
JavaScript
$('.message').contents().each(function() {
if (this.nodeType === 3 && !$.trim(this.nodeValue)) {
$(this).remove();
}
});
$('.message').append('<span>Menu 3</span>');
console.log($('.message').html());