Update dom.js

2025-09-20 23:52:19 +00:00
parent 3d007f4df1
commit c3b55ad65d

@@ -2,12 +2,29 @@
import { el, dom } from './dom.js import { el, dom } from './dom.js
``` ```
## el(attr, children) ## el.TAG(attr, children) → Element
This is a proxy for `DomHelper.create`, saving you a few characters. TAG can be any valid HTML tag, attr is an object of attributes to assign using `apply()`, and children is an array of children to append using `append()`.
## class dom (DomHelper) ## class dom (DomHelper)
### create(element, attr, children) ### create(element, attr, children) → Element
### apply(element, attributes) ### apply(element, attributes)
### append(element, children) Apply will apply all values in the **attributes** object as attributes to the element, with a few exceptions:
- If the value of the attribute is null, the attribute will be removed rather than set.
- If the value of the attribute is true, the attribute value will be the same as the attribute name.
- If the attribute name starts with `on:`, for example `on:click`, the value must be a callable which will be set as a listener for the specified event. No attribute will be added in this case.
Note: Since this method is called from `el()` and `create()`, the above rules are valid with those methods as well.
### append(element, children)
Append will add all values and elements in the **children** array as children to the element, with a few exceptions:
- If the child is `null`, it will be skipped. This lets you add children conditionally by nulling them if undesired.
- If the child is a string, it will be added as a text node.
Note: Since this method is called from `el()` and `create()`, the above rules are valid with those methods as well.