JSFiddle - React, Tailwind, and code Playground

HTML

<h1>This is a test</h1>
<h1>This is a test2</h1>
<h1 class="blah blah"><a href="#">This is a test</a></h1>

CSS

span {
   color: red
}

JavaScript

$('h1').each(function(){
     var self = $(this);
     var p = self.text().split(' ');
     var html = self.html().replace(p[0], '<span>'+ p[0] +'</span>');
     self.html(html);
});