const doc = new DOMParser().parseFromString("<xml></xml>", "application/xml");
const comment = doc.createComment(
"This is a not-so-secret comment in your document",
);
doc.querySelector("xml").appendChild(comment);
console.log(new XMLSerializer().serializeToString(doc));
// Displays: <xml><!--This is a not-so-secret comment in your document--></xml>Document: createComment() method / notebook
Document: createComment() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.