Try the following code (either with Edge/Chrome or Firefox, but not in the snippet). The console.log()
just gives different outputs, why did this happen?
It's really strange to see this.
const para = document.querySelector('p'),
text = para.childNodes.item(0),
range = document.createRange()
range.setStart(text, 0)
range.setEnd(text, 1)
const clonedContents = range.cloneContents()
// - Chrome/Edge -
// string: #docment-fragment
// - Firefox -
// DocumentFragment []
console.log('cloned contents: ', clonedContents)
// - Chrome/Edge -
// a real #docment-fragment
// - Firefox -
// DocumentFragment [ #text ]
console.log('cloned contents: ', range.cloneContents())
inContentsNode = clonedContents.childNodes.item(0)
// without this line, console.log would work as expected
para.after(inContentsNode)
<body>
<p>a</p>
</body>