I want to highlight the specific word index passed by function, initially function added on a button click. The problem is when i reassign 'document.getElementById('inputText').innerHTML = filterText;' it re-renders the page(Because there is iframe video ) and there is an iframe and another thing which are conflicting.
function makeALlIndex() {
defaultText = document.getElementById('inputText').innerHTML;
}
function changeColor(index, word) {
myText = defaultText;
var filterText = myText.substr(0, index) + '<span class="highlightClass">' + word + '</span>' + myText.substr(index + word.length);
document.getElementById('inputText').innerHTML = filterText;
}
Html
<body onload="makeALlIndex()">
<div id="inputText">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.
<button onclick="changeColor(0,'')">click me</button>
</div>
</body>