const doc = new DOMParser().parseFromString("<div>Hello world</div>", "text/html");
function convertNode(node: any) {
if (!node.childNodes) {
return;
}
node.childNodes.forEach((childNode: Node) => {
if (childNode.nodeType === NodeType.TEXT_NODE && childNode.textContent.trim()) {
childNode.nodeValue = 'foo';
}
convertNode(childNode);
});
}
if (doc) {
convertNode(doc);
console.log(doc.body.innerHTML, doc.body.innerText);
}
So as a result doc.body.innerHTML will still be <div>Hello world</div> while doc.body.innerText will correctly be foo which is incorrect. The new HTML value should be <div>foo</div>.
Hi! Let's say I have this code:
So as a result
doc.body.innerHTML
will still be<div>Hello world</div>
whiledoc.body.innerText
will correctly befoo
which is incorrect. The new HTML value should be<div>foo</div>
.I feel like this is quite a critical issue 😢