When adding child elements to the parent element in the DOM not all of them get added. The console output correctly lists the child elements to add to the parent element. Appears as though the appendChild function in org.w3c.dom.Node in the Kotlin JS standard library isn’t behaving properly. Below is the defined function where the issue occurs:
private fun changeElement(element: ParentHtmlElement, domElement: Element) {
val newChildren = element.toDomElement().childNodes.asList()
domElement.clearAttributes()
domElement.clearChildren()
element.attributes.forEach { (key, value) -> domElement.setAttribute(key, value) }
if (element.id.isNotEmpty()) domElement.id = element.id
if (element.txtContent.isEmpty()) {
domElement.textContent = null
} else {
domElement.textContent = element.txtContent
}
// TODO: Remove the line below.
newChildren.forEach { println("Item: ${it.textContent}") }<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/flex019/uploads/kotlinlang/original/2X/4/435087ac2ad1e26c9a1a0a15d2148dc4324bd537.png" width="657" height="410">
newChildren.forEach { domElement.appendChild(it) }
}
Is there a workaround for adding child elements to a parent element? Below is a screenshot of the results: