0

Attempting to write out an edited JSDOM instance using document.toString however it serializes as [object Document]. What method should we call to get the document markup as a String or is there a better way to serialize it in node. Currently I'm making this call:

     fs.writeFileSync(target, document.toString());
Ole
  • 41,793
  • 59
  • 191
  • 359
  • https://stackoverflow.com/questions/31828568/jsdom-in-nodejs-how-do-i-get-back-the-manipulated-html – finnan Mar 09 '18 at 02:26

1 Answers1

2

As per the documentation (https://github.com/jsdom/jsdom):

const dom = new JSDOM(`<!DOCTYPE html>hello`);

dom.serialize() === "<!DOCTYPE html><html><head></head><body>hello</body></html>";

// Contrast with:
dom.window.document.documentElement.outerHTML === "<html><head></head><body>hello</body></html>";
Robert Moskal
  • 21,737
  • 8
  • 62
  • 86