I Have a Node from DOM, in this node I find a string and I replace it before and after with open/close span tag in this way:
tmp(node){
if (node.nodeType === 3) { // Node.TEXT_NODE
var text = node.data.replace(/In eterni Dei/, "<span>In eterni Dei<span>");
if (text != node.data)
node.data = text;
} else if (node.nodeType === 1) { // Node.ELEMENT_NODE
for (var i = 0; i < node.childNodes.length; i++) {
this.tmp(node.childNodes[i]);
}
}
}
This solution work but replace only the string, I need that the replacement can convert my replaced string in HTML DOM elements in the same position