JSFiddle - React, Tailwind, and code Playground
HTML
<div id="content"> </div>
JavaScript
var text = " How to replace string in jquery or javascript one at a time !!! How to replace string in jquery or javascript one at a time !!! How to replace string in jquery or javascript one at a time !!! ";
var textToReplace = "jquery";
var textReplaceWith = "<span style='background-color:yellow'>JQUERY</span>"
var numOfOccur = text.match(/jquery/g).length;
while(numOfOccur-- > 0){
text = text.replace(textToReplace ,textReplaceWith );
}
$("#content").html(text);
alert(text);