Initiates a CalDom instance.
(Optional) "+tag" creates a new Element.
'<tag></tag>' creates specified HTML structure. "~svg_tag" creates a SVG element.
Otherwise, it can be a CSS Selector, an XPath query starting with "$", a CalDom instance, a single Node/Element, an array of Nodes or a NodeList/HTMLCollection.
(Optional) Child elements to be passed into append(). Can be CalDOM/Node/String or an array of them. See append() for all possibilities.
This might be useful for code-clarity at render() function for reactive components. See examples at react().
(Optional) parent_window default to current window. Use this to work with iframes or external windows.
{CalDom} A new CalDom instance with created/found elements.
Nodes/Elements of this CalDom instance.
(Note that directly changing items here is not recommended.)
First Node of this CalDom instance. .elem == .elems[0]
Get a new CalDom instance with matching descendent elements for all elements in this CalDom instance.
Note: This could return duplicates when there are inter-connected elements in this CalDom instance.
CSS Selector to find or XPath query starting with "$"
{CalDom} A new CalDom instance with found elements.
Get a new CalDom instance with i-th element in this CalDom instance.
Can be a zero-based index or a minus(-i) index from end (Eg: -1 returns last element)
{CalDom} A new CalDom instance with the i-th element
Get a new CalDom instance with immediate parent(s) or n-th parent(s) or parent(s) matching the CSS selector. (If this CalDom instance has more than 1 element, parents of all of them are included.)
(Optional) Default is immediate parent. If a number is given, n-th parent is returned (zero-based). If a string is given, first parent(s) to match the CSS selector is returned.
{CalDom} A new CalDom instance with matched parents. Multiple parents will be returned if there are 2 or more elements in this CalDom instance.
Get a new CalDom instance with children of all elements in this CalDom instance. (If this CalDom instance has more than 1 element, children of all of them are included.)
(Optional) CSS selector to match
{CalDom} A new CalDom instance with children.
Iterate each element in this CalDom instance with a callback.
Function to callback. Callback is called with 2 arguments: callback(elem: Node, index: Number). The enumeration stops if the callback returns false.
{CalDom} Returns current CalDom instance
Iterate each element in this CalDom instance with a callback and get an array of callback's returned values.
Function to callback. Callback is called with 2 arguments: callback(elem: Node, index: Number).
{Array} An array of values returned by the callback.
Get or set innerHTML of all elements in this CalDom instance.
(WARNING: This might lead to XSS vulnerabilities. Use text() or append("text_content") if you're only updating text).
(Optional) A HTML string or an array of HTML strings to set at corresponding n-th element.
If not given, an array of innerHTML for all elements in this CalDom instance is returned.
{ CalDom | Array<String> } If html_or_html_array param is given, current CalDom instance is returned.
Otherwise, an array of innerHTML from all elements in this CalDom instance is returned.
Get or set textContent of all elements in this CalDom instance.
(Optional) Text or an array of text to set at corresponding n-th element.
If not given, an array of textContent is returned.
{ CalDom | Array<String> } If text_or_text_array is given, current CalDom instance is returned.
Otherwise, an array of textContent from all elements in this CalDom instance is returned.
Get or set value property of elements in this CalDom instance.
(Optional) Value or array of values to to be set at corresponding n-th element.
If not given, array of values will be returned.
{ CalDom | Array<String> } If val_or_val_array is given, current CalDom instance is returned.
Otherwise, array of value from all elements in this CalDom instance is returned.
Get or set attribute(s) of elements in this CalDom instance.
Attribute name as a String or { key: value, ... } object to set multiple attributes
(Optional) Value or array of values to be assigned at corresponding n-th element.
If not given, an array of attribute values for the given key is returned.
{ CalDom | Array<String | Number> } If it's a set request, current CalDom instance is returned.
Otherwise, an attribute value array from all elements in this CalDom instance is returned.
Get or set variable(s) at elements' root. Other than assigning custom data of any type at elements' root, this can be used to access all properties/attributes of elements as well.
Warning: Look out for untracked circular references that might lead to memory leaks.
Variable name as a String or { key: value, ... } object to set multiple variables.
(Optional) Value or an array of values to be to be assigned at the corresponding n-th element. If empty, an array of given key's values is returned.
{CalDom | Array} If it's a set request, this chainable CalDom instance is returned.
Otherwise, a value array from all elements in this CalDom instance is returned.
Store & retrieve { key: value, ... } data from elements in this CalDom instance.
(Data is stored at element._data. However, _data location might change over time, avoid accessing it directly as possible.)
Warning: Look out for untracked circular references that might lead to memory leaks.
Can be any javascript Object, usually a string.
(Optional) Can be any javascript Object or an array of Objects to be to be assigned at the corresponding n-th element.
If it's a set request, this CalDom instance is returned.
Otherwise, an array of values for the provided key from all elements is returned.
Get & set CSS style rule(s) of elements in this CalDom instance.
CSS property name or { property: value, ... } object to set multiple rules
CSS value or an array of values to be set at n-th element for the given CSS property name.
{CalDom | Array<String | Number>} If it's a set request, this CalDom instance is returned.
Otherwise, a CSS value array for the given property from all elements in this CalDom instance is returned.
Add class name(s) to elements in this CalDom instance.
A single class name or multiple class names separated by spaces or as an array.
{CalDom} Returns this CalDom instance.
Remove class name(s) from elements in this CalDom instance.
A single class name or multiple class names separated by spaces or as an array.
{CalDom} Returns this CalDom instance.
Set display CSS property of all elements in this CalDom instance.
(optional) Display value. Default to "block"
{CalDom} Returns this CalDom instance.
Set display CSS property of all elements in this CalDom instance to "None".
{CalDom} Returns this CalDom instance.
Add event listeners to elements in this CalDom instance.
A single event name or multiple event names separated by spaces or as an array.
Callback function to handle the event.
(Optional) options to pass into addEventListener's 3rd param.
{CalDom} Returns this CalDom instance.
Remove event listeners from elements in this CalDom instance.
A single event name or multiple event names separated by spaces or as an array.
Callback. The same callback provided at on() or Node.addEventListener() should be provided.
(Optional) options to pass into removeEventListener's 3rd param.
{CalDom} Returns this CalDom instance.
Append/Move elements to first element of this CalDom instance.
Null and undefined inputs are silently ignored. Note that if you append an existing element, it is moved to the new destination (not cloning).
First argument can be a CalDom instance, a Node/String or an array of Node/String.
Provided elements are added to the first element of this CalDom instance. This is XSS safe as it's considering String inputs as a text node. Use .html() or init _("<h1></h1>") to inject HTML.
See the examples for wide range of possibilities.
(Optional) If the first argument is not an array-type, all ...arguments are added to the first element of this CalDom instance.
{CalDom} Returns this CalDom instance.