0

I am trying to replace all links in body to spans like this.

map((body) => {
      let dom = parse(body.toString());
      dom.querySelectorAll('a').forEach((link) => {
        dom.exchangeChild(link, parse(`<span>lalala</span>`));
      });
      return dom;
    })

Any suggestions or guesses why this is not working?

JDB
  • 25,172
  • 5
  • 72
  • 123
karina
  • 789
  • 9
  • 26
  • 1
    Can you please expound upon "_this is not working_"? I am not familiar with `exchangeChild()`. Are you perhaps looking for [`replaceChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/replaceChild)? – JDB May 04 '23 at 14:32
  • 1
    Never mind about `replaceChild()`... looks like [`node-html-parser`](https://www.npmjs.com/package/node-html-parser) returns an enhanced HTMLElement with custom methods, including `exchangeChild()`. – JDB May 04 '23 at 14:40

0 Answers0