I am trying to insert span element in a nodeValue, but it adds to whole element. I only want the span content. How can I do it?
let allElements = document.querySelectorAll('*');
allElements.forEach(function (element) {
element.childNodes.forEach(function (el) {
if (!el.nodeValue) return;
el.nodeValue = el.nodeValue.replace(word, `<span class='rainbow'>${word}</span>`);
});
});