Search code examples
kotlinkotlin-js-interop

KotlinJS unresolved reference element.style


I want to change the style of an element created using document.createElement("button").

I tried using:

element.style.width = "50px"

However, the style field cannot be found.


Solution

  • The Element needs to be cast to the more specific HTMLElement type:

    val button = document.createElement("button") as HTMLElement
    button.style.width = "50px"