document.createComment All In One
document.createComment
document.createComment("auth")
<!--auth-->
MDN
XML / HTML
const docu = new DOMParser().parseFromString("<xml></xml>", "application/xml");
const comment = docu.createComment("This is a not-so-secret comment in your document");
docu.querySelector("xml").appendChild(comment);
console.log(new XMLSerializer().serializeToString(docu));
// <xml><!--This is a not-so-secret comment in your document--></xml>
https://developer.mozilla.org/en-US/docs/Web/API/Document/createComment
Comment
let comment = new Comment("Test");
console.log(`comment =`, comment)
// comment = <!--Test-->
https://mdn1.moz.one/en-US/docs/Web/API/Comment/Comment?language=en-US
https://developer.mozilla.org/en-US/docs/Web/API/Document/Comment
https://developer.mozilla.org/en-US/docs/Web/API/Comment/Comment
https://dom.spec.whatwg.org/#ref-for-dom-comment-comment①
demos
const removeElement = (el) => {
// 在绑定元素上存储父级元素
el._parentNode = el.parentNode
// 在绑定元素上存储一个注释节点
el._placeholderNode = document.createComment("auth")
// 使用注释节点来占位
el.parentNode?.replaceChild(el._placeholderNode, el)
}
https://juejin.cn/post/7209648356530896953