Here's how I'd turn every word in an element into a span, I'd avoid regex, since DOM tools are provided by default.
var elementWithWords = document.getElementById('myElementId'); //get a reference to your element
var words = elementWithWords.textContent.split(/\s/); //split on whitespace to get individual words
elementWithWords.textContent= ''; //clear out the html of the element
for(var i = 0; i < words.length; i++) { //for each word, create a span and append it to the original element
var word = words[i];
var wordSpan = document.createElement('span');
wordSpan.textContent = word;
elementWithWords.appendChild(wordSpan);
}
EDIT:
You could probably use the first with some finangling, however, below should work and keep your formatting. Note, anytime you set the innerHTML of something, be aware that it potentially opens you up to Cross Site Scripting Attacks.
var elementWithWords = document.getElementById('myElementId'); //get a reference to your element
var words = elementWithWords.textContent.split(/\s/); //split on whitespace to get individual words
for(var i = 0; i < words.length; i++) { //for each word, create a span and append it to the original element
var word = words[i];
elementWithWords.innerHTML = elementWithWords.innerHTML.replace(word, "<span>" + word + "</span>");
}