I have the "on_event
" JS function:
function on_event(event) {
console.log(event);
}
And I have the "button
" HTML element builder in Rust:
let window = web_sys::window().expect("no `window` object");
let document = window.document().expect("no `document` object");
let body = document.body().expect("no `body` object");
let button = document.create_element("button")?;
// ...
body.append_child(&button);
How to link the "on_event
" JS function with the "button
" HTML element from the Rust code?
At the end I need something like:
button.add_event_listener("click", "on_event"); // <- What I need to use here instead of this code