So I have a DOM element that looks like this:
<span>text</span>
<b>some more text</b>
even more text here
<div>maybe some text here</div>
My question is how do I swap text
for candy
so it looks like this:
<span>text</span>
<b>some more text</b>
even more *candy* here
<div>maybe some text here</div>
I've tried a .replace
with regex already but it swaps all the text occurrences.
Also I do not know where the text without tags will be. It could be in the middle at the beginning or at the end, (basically anywhere) I can't remove the child nodes either, because I don't know their positions and also if there is a <script>
child it would probably rerun when I add it again at the end of all the text manipulation.
Can anyone point me in the right direction?