JSFiddle - React, Tailwind, and code Playground
HTML
<div id="replace-me">Hello, world</div>
JavaScript
replaceWordAtIndex = function (text, index, replacement) {
text = text.split(' ');
text[index] = replacement;
text = text.join(' ');
return text;
}
wrapWordAtIndex = function (text, index, before, after) {
text = text.split(' ');
text[index] = before + text[index] + after;
text = text.join(' ');
return text;
}
var obj = document.getElementById('replace-me');
obj.innerText = replaceWordAtIndex(obj.innerText, 1, 'Universe');
obj.innerHTML = wrapWordAtIndex(obj.innerText, 1, '<b>', '</b>');