Webru
Frequently used javascript functions for Rust and WebAssembly
webru is a binding for web-sys
This crate assumes that you will only use this crate inside browser. Not any other javascript runtime such as Node.js
Example
use Closure;
use JsCast;
use ;
use console_log;
use ;
// javascript `Window.alert()` method
alert;
// getting the <body> tag/element
let body: HtmlElement = body;
// creating a <h1> tag using javascript `document.createElement()` method
// This function will return the newly created element/tag
let h1: Element = create_element;
// adding some attributes to <h1> tag
h1.set_id; // html `id` property
h1.set_class_name; // html `class` property`
h1.set_inner_html;
// pushing the <h1> tag into the DOM
body.append_child;
// This closure will be called the <button> will be clicked
let cb: = callback;
// creating a <button> element
let button: HtmlElement = create_element
.
.unwrap
.clone;
// adding some attributes to <button> tag
button.set_inner_html; // innerHTML property
button.set_onclick; // onclick event
cb.forget;
// pushing the <button> tag into the DOM
body.append_child;
// javascript `setTimeout()` method
set_timeout;
// getting the <h1> element from the DOM
// javascript `document.getElementById()` method
let h1_from_dom: = get_element_by_id;
assert_eq!;