I am iterating over all the text node in an html document in order to surround some words with a specific span.
Changing the nodeValue doesn't allow me to insert html. The span is escaped to be shown in plain text and I do not want that.
Here is what I have so far :
var elements = document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
  var element = elements[i];
  for (var j = 0; j < element.childNodes.length; j++) {
    var node = element.childNodes[j];
    if (node.nodeType === Node.TEXT_NODE) {
      node.nodeValue = node.nodeValue.replace(/Questions/, "<span>Questions</span>");
    }
  }
}<p>Questions1</p>
<p>Questions 2</p>
<p>Questions 3</p>
<p>Questions 4</p> 
     
     
     
    