Javascript: replace 'g' character
javascript, replace
Solution
Try use `.innerText` instead of `.innerHTML`, like so
var myDiv = document.getElementById('myDiv');
var text = myDiv.innerText || myDiv.textContent || '';
myDiv.innerHTML = text.replace(/g/g, 'a');
// or without variable
// myDiv.innerHTML = (myDiv.innerText || myDiv.textContent || '').replace(/g/g, 'a');
<div id="myDiv">aaa>aga</div>
Problem
I would like to replace `g` characters on the following innerHTML div: ``` <div id="myDiv">aaa>aga</div> ``` I used ``` var myDiv = document.getElementById('myDiv'); myDiv.innerHTML = myDiv.innerHTML.replace('g','a'); ``` Unfortunately, this replace also the `>` character by `&at;`. How can I do to avoid this behavior ?