JSFiddle - React, Tailwind, and code Playground

HTML

<h1>Each word will be wrapped in a span.</h1>
<h2>This is an h2 element.</h2>
<p>A second paragraph here.</p>
Word: <span id="word"></span>

JavaScript

// wrap words in spans
$('p,h1,h2,h3').each(function() {
 var $this = $(this);
           $this.html($this.text().replace(/\b(\w+)\b/g, "<span>$1</span>"));
});

// bind to each span
$('p,h1,h2,h3').find("span").hover(
 function() { 
  $('#word').text($(this).css('background-color','#ffff66').text()); 
 },function() { 
  $('#word').text(''); $(this).css('background-color',''); 
 }
);