I am trying to work out how to replace any instance of text on page matching a certain phrase with a HTML tag - the contents should remain the same.
bold("Hello")
The code above should be replaced with:
<b>Hello</b>
Here is the code that I am currently using:
node.data = node.data.replace('bold("','<b>');
node.data = node.data.replace('")','</b>');
The problem with this is that rather than creating a <b>
tag, it converts the <
and >
into their HTML entities - < >.
Also, it seems unpractical to replace all instances of ")
with </b>
.
What would be the best way to achieve this.
I would appreciate any help with this, thank you!