I have an editable% color where I can capture the whole text inside it. Dai I want that in every occurrence of a certain word that word be replaced by another. Very simple.
The code I tried did not work. It itself works only that the output does not work (which in the case is the input itself). But if it's put in div
for example, it works.
JS
function teste(){
var campo = document.getElementById('editorid').textContent;
var docrg = /palavra/g; // procurar por 'palavra' sem ignorar case
campo.replace(docrg, "outrapalavra"); // replace 'palavra' por 'outrapalavra'
}
document.getElementById('botao').addEventListener('click',teste,false);
HTML
<div id="editorid" contenteditable="true"></div>
<button id="botao">clica</button>
CSS (optional only to show border)
#editorid{
width: 500px;
height: 500px;
border: 1px solid black;
padding: 10px;
}
Note: This problem is just a module of a text editor I'm trying to do.