Skip to content

1.2.8: Add support for custom event handlers.

Compare
Choose a tag to compare
@Tao-VanJS Tao-VanJS released this 23 Jan 23:14
· 260 commits to main since this release

In this release, we changed the implementation of event handlers in VanJS. Instead of registering event handlers via on... property, we changed to use addEventListener and removeEventListener to register and unregister event handlers.

As a result of the change, you can set custom event handlers via tag functions:

const {button, div, p} = van.tags

const dom = div(button({oncustom: () => van.add(dom, p("Event triggered!"))}, "Button"))
van.add(document.body, dom)

dom.querySelector("button").dispatchEvent(new Event("custom"))

See the release announcement: #246