https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
g

Gunslingor

03/23/2020, 4:59 PM
Why does this work:
Copy code
document.body?.appendChild(renderer.domElement)
While this doesn't?
Copy code
val target = document.getElementById("right_pane")?
target?.appendChild(renderer.domElement)
document.body? is an Element and document.body? is an HTML element.... not sure why there are two but there has to be a converter or something... or someway to make this work. Elements seems to allow appending a string as HTML via innerHTML while HTMLElements seem to do something with Nodes... don't really get this, feels like object interfaces aren't formalized.
a

araqnid

03/23/2020, 6:26 PM
HTMLElement is just a subtype of element. By “doesn’t work”, do you mean it doesn’t compile (you have an extra “?” on the first line) or it has no effect?
This compiles for me:
Copy code
val domElement = document.create.div {
        p { }
    }

    document.body?.appendChild(domElement)
    document.getElementById("xxx")?.appendChild(domElement)
g

Gunslingor

03/23/2020, 6:29 PM
Yeah, it compiles but with unintended results. I actually figured it out as soon as you messaged me, lol. the missing word was "apply" and then it appears I had access to the two things I needed to append and html element string and also a child node
Copy code
document.getElementById("right_pane")?.apply {
    appendElement("div") {
        innerHTML = ProjectionToolbar().view
    }
    appendChild(viewer.renderer.domElement)
}
I can be tough to navigate someone else's objects, lol