JSFiddle - React, Tailwind, and code Playground
HTML
<div id="para">manoj</div>
<div id="manoj">replaceto</div>
<div class="check"></div>
JavaScript
var suggestionList=['manoj','manoj dhiman','manoj kumar'];
$list=$('.check');
for(var i=1; i<suggestionList.length; i++)
{
$list.append("<li>" + suggestionList[i] + "</li>");
// attach handler for click on the suggestions
}
$list.find("li").click(function() {
changewith=$(this).html();
change(suggestionList[0], changewith);
});
function change(changeto,changewith)
{
var replaceto=document.getElementById(changeto).innerHTML;
var replacewith=changewith;
var text1=document.getElementById("para").innerHTML;
document.getElementById("para").innerHTML='';
var afterRe=text1.replace(changeto,replacewith);
document.getElementById("para").innerHTML=afterRe;
}