Skip to content
Sergey Mashkov edited this page Nov 15, 2017 · 5 revisions

Events

Many html elements have a set of events that could be handled. To handle an event you have to specify corresponding attribute value. In streaming mode you can specify only plain text on both JVM and browsers platforms. However in the DOM mode of browser target you also can specify a lambda to be executed as event handler if you import kotlinx.html.js.*

div {
    onClickFunction = { event ->
        window.alert("Kotlin!")
    }
}

🔴 Notice that there are both var onClick: String and var onClickFunction: (Event) -> dynamic in JS. The first one is a string property and works both on server side and client side. The second one property is only available in JS and provides way to set lambda handler directly. There is no way to serialize lambda to string on server side.