In all the possible answers in SO, they also change the attributes.
<div id="content">
<a href="foo.com/first-foo/method">The foo method</a>
<h1>the foo.</h1>
<p>While the foo is red</p>
<div class="_special-foo">
Some other foo, might not be foo.
</div>
</div>
<script>
let theFoo = document.getElementById('content').innerHTML;
document.getElementById('content').innerHTML = theFoo.replace(/foo/g, 'Foo');
</scrip>
That is changing all foo
to Foo
, is okay but not, because it also changes the href
, class
and/or possible id
's, I haven't found any pattern. In most cases, if not changing the href
, it will change the class
, if not, then it missed some . or , after in other cases will miss the whole thing.
So how to replace just string without touching/changing class, id, href attributes.?
Thank you.