macro_rules! html {
($($args:tt)+) => { ... };
}Expand description
Used to build a Dom and is a wrapper over DomBuilder<A>.
By default the macro is internally typed to HtmlElement.
Note if you want to generate SVG make sure to use the svg! macro.
html!("html_tag", { .dom_builder_methods })// <div></div>
html!("div");
// <my-tag></my-tag>
html!("my-tag");
// <div>Hello world</div>
html!("div", {
.text("Hello world")
});
// <div class="my-class">Hello world</div>
html!("div", {
.text("Hello world")
.class("my-class")
});It can be typed to any element that
impl JsCast.
html!("html_tag" => internal_element_type , { .dom_builder_methods })e.g. HtmlInputElement
// <input placeholder="type here">
html!("input" => HtmlInputElement, {
.attr("placeholder", "type here")
});Why would you want to know the type? Well once you start using some of the DomBuilder methods knowing the html element type allows you to call its associated methods:
html!("input" => HtmlInputElement, {
.before_inserted(|input| {
// .value() is a method on HtmlInputElement, but not on HtmlElement
if input.value().is_empty() {
input.set_value("Hello")
}
})
});