A string starting with < (after whitespace) is markup; any other string is a selector. Collections must contain EventTargets; anything else throws a TypeError.
| Call | Returns | Semantics |
df$(selector, context?) | DfQuery<Element> | querySelectorAll on context (Document, Element or DocumentFragment), default the document. Tag names give precise types: df$("button") is DfQuery<HTMLButtonElement>. |
df$("<markup>"), df$(vnode) | DfQuery<Node> | New detached nodes; several roots allowed. |
df$(target | targets) | DfQuery<T> | Wraps an EventTarget (element, document, window) or an iterable or array-like of them. |
df$(fn) | DfQuery<Document> | Runs fn(df$) on DOMContentLoaded, or in a microtask when the document is already parsed. |
df$(), df$(null) | DfQuery | An empty selection. |
[i], .length, .get(i?), .toArray() | item or array | Array access; get() and toArray() return copies, get(-1) counts from the end. |
.eq(i), .first(), .last() | new selection | One item; negative indices count from the end. |
.each(fn) | this | jQuery order (index, element) with this bound to the element; returning false stops. |
.find(css), .filter(css | fn), .is(css) | selection, boolean | Descendants, matching subset, any match. .find(fn) keeps the native Array behavior. |
.parent(), .children(css?), .closest(css), .next(), .prev() | new selection | Element traversal, deduplicated in encounter order. |
.map(), .slice(), .flat() | plain Array | Species-based Array methods return ordinary arrays. |
Getters read the first element; setters write every element and return the selection. Non-element targets are skipped where a method needs an element.
| Method | Semantics |
.attr(name, value?) | A missing attribute reads null, an empty selection undefined. Setting null removes it. |
.prop(name, value?) | Native JS properties. innerHTML, outerHTML, textContent and innerText writes throw: use the content methods. |
.data(name, value?) | dataset with camelCase keys; values are strings, null deletes. No cache, no JSON coercion. |
.css(name | map, value?) | Getters read the computed style, setters write inline style. camelCase and custom properties work; no implicit px. |
.addClass(), .removeClass(), .toggleClass(names, force?), .hasClass() | Whitespace strings or string arrays. removeClass() without arguments clears the attribute. |
.val(value?) | Control values; a multiple select reads and writes string arrays, an array on checkboxes and radios sets checked by value. Dispatches no input or change. |
Content methods accept markup strings, VNodes, nodes, NodeLists and fragments. With several targets, nodes are cloned for all but the last target, which receives the originals.
| Method | Returns | Semantics |
.morph(content, options?) | this or Promise<this> | Morphs the content into every element. Passing transition makes it async, even { type: "none" }. |
.html(content?, options?) | string or as morph() | Without arguments: the first element's innerHTML (its open shadow root's for normal elements). With content: morph(). |
.text(value?) | string or this | Reads the concatenated text. Writes literal text, never parsed as HTML; Text and CDATA nodes keep their identity. |
.empty() | this | Morphs an empty list into every element. |
.append(), .prepend(), .before(), .after() | this | Exact inserts with insertBefore. A batch that would insert an ancestor into its descendant throws before any write. |
.replaceWith(content) | this | Inserts the content before each target, then removes the target. |
.appendTo(target) | inserted nodes | Appends this selection to a selector, root or collection and selects the inserted nodes. |
.remove() | this | Detaches every node after running morph's cleanup, which also removes on() listeners. |