Skip to content

dom.js (legacy)

Sean edited this page May 25, 2019 · 1 revision

I rewrote dom.js so the following is no longer relevant.

(dom.js doesn't really have a name; I usually just copypaste the code and change a few things, oof)

createElement takes in the tag name and an optional data object.

All of the properties of data are optional. undefined values are ignored (but not other falsey values).

classes is either a space-separated string or an array of classes.

children is an array of strings, which get converted to text nodes, or nodes

attributes is an object mapping attribute names to their values; it attempts to do elem.attr first then uses setAttribute

listeners is an object mapping event names to their listener function

styles is an object mapping styles to their values; CSS variables are supported

html is a string containing the inner HTML, which is set last, so it'll override whatever is in children

ripples will make the element have the ripple effect when clicked on if set to a truthy value

Some other iterations of dom.js have support for namespaces for SVG elements; Ugwisha's doesn't.

There is also createFragment, which turns an array of nodes into a document fragment, and deundefine, a helper function that removes undefined values from an array or object.

Clone this wiki locally