Hi i am not able to replace the highlighted text..here is the code of my sample which just does highlighting:
CSS:
.highlight
{
background-color:yellow;
}
JS:
function highlight(text)
{
var inputText = document.getElementById("inputText");
var innerHTML1 = inputText.innerHTML;
var index = innerHTML1.indexOf(text);
if ( index >= 0 )
{
innerHTML1 = innerHTML1.substring(0,index) + "<span class='highlight'>" + innerHTML1.substring(index,index+text.length) + "</span>" + innerHTML1.substring(index + text.length);
inputText.innerHTML = innerHTML1;
}
}
HTML:
<button onclick="highlight('fox')">Highlight</button>
<div id="inputText">
The fox went over the fence
</div>
Let me know the code for replacing the highlighted text..
While googling, i have got one link..but it is creating a new node..here is the link http://stackoverflow.com/questions/3997659/replace-selected-text-in-contenteditable-div?rq=1