I thought that this would be rather straightforward, but I think the keywords are just too general so I keep getting query results for things like this and this.
Basical
Dropping down to the DOM lets you see text node contents when checking siblings.
Something like:
function combineSpans(span, nextspan)
{
var follower = span.nextSibling;
var concat = true;
while (follower != nextspan)
{
if (follower.nodeName != '#text')
{
concat = false;
break;
}
var len = follower.data.trim().length;
if (len > 0)
{
concat = false;
break;
}
follower = follower.nextSibling;
}
if (concat)
{
$(span).text($(span).text() + " " + $(follower).text());
$(follower).remove();
}
}
Using this with your HTML in this CodePen.