HTML Element Prototypes
HTML values expose attribute and children helpers.
let btn = <button>Click</button>
btn.setAttribute("id", "main-button")
println(btn.getAttribute("id"))Literal calls
Section titled “Literal calls”Store a literal in a variable before calling its methods. Direct prototype calls on literals are limited by the current parser.
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
setAttribute(name: string, value: any) | void | Sets an attribute. |
removeAttribute(name: string) | void | Removes an attribute. |
getAttribute(name: string) | any | Returns an attribute value, or nil. |
hasAttribute(name: string) | bool | Checks whether an attribute exists. |
children() | [](html | string) | Returns the element’s children. |
setChildren(children: [](html | string)) | void | Replaces the element’s children. |
Indexed Attributes
Section titled “Indexed Attributes”HTML elements also support indexed access through internal __get__ and __set__.
let btn = <button>Click</button>
btn["id"] = "save-button"
println(btn["id"])Attribute names are normalized to kebab-case.
let btn = <button>Click</button>
btn.setAttribute("dataUserId", "123")
println(btn.getAttribute("data-user-id"))Attributes
Section titled “Attributes”let btn = <button>Click</button>
btn.setAttribute("class", "primary")btn.setAttribute("disabled", true)
println(btn.hasAttribute("class"))println(btn.getAttribute("class"))
btn.removeAttribute("disabled")Reading Children
Section titled “Reading Children”let box = <div>Hello</div>
let children = box.children()
println(children)Replacing Children
Section titled “Replacing Children”let box = <div>Hello</div>
let children: [](html|string) = []children.push(<span>Nubo</span>)children.push("!")
box.setChildren(children)
println(box.children())