Gets the child nodes wrapped in the most specific JJ wrappers available.
The wrapped child nodes.
Gets the parent node wrapped in the most specific JJ wrapper available.
The wrapped parent node, or null if this node has no parent.
Appends children to this Element.
The children to append.
This instance for chaining.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Maps an array to children and appends them.
This instance for chaining.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Appends an array of children to this Element.
The children to append.
This instance for chaining.
This is the array-based companion to addChild.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Clones and appends template-like input to this node.
This instance for chaining.
Supports HTML strings, native template sources, native Nodes, and any JJ wrapper via JJN. Wrapper inputs are unwrapped and cloned before append.
Creates a Text node from a string and appends it to this Node.
The text to add. The actual text that's added follows the rules in document.createTextNode() which is basically what you get from String()
This instance for chaining.
el.addText('Hello ')
el.addText('World')
// Behaves like document.createTextNode('Hello World') and appends it to el
// Falsy values are converted to their string representation, except for empty string which is added as is.
el.addText('Hello', '', 'world', null, undefined, '!!!') // Adds 6 text nodes with content 'Hello', '', 'world', 'null', 'undefined', and '!!!' respectively.
Removes all children from this Element.
This instance for chaining.
Finds the first element matching a selector within this Element.
The CSS selector.
Whether to throw an error if not found. Defaults to false.
The wrapped element, or null if not found and required is false.
Finds all elements matching a selector within this Element.
The CSS selector.
An array of wrapped elements.
Removes an event listener.
The name of the event.
The event handler.
Optionaloptions: boolean | EventListenerOptionsOptional event listener options or boolean.
This instance for chaining.
Adds an event listener.
The name of the event.
The event handler.
Optionaloptions: AddEventListenerOptionsOptional event listener options.
This instance for chaining.
Prepends children to this Element.
The children to prepend.
This instance for chaining.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Maps an array to children and prepends them.
This instance for chaining.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Prepends an array of children to this Element.
The children to prepend.
This instance for chaining.
This is the array-based companion to preChild.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Removes this node from its parent.
This instance for chaining.
Runs a function in the context of this JJET instance.
The synchronous function to run. this inside the function will refer to this JJET instance, and the wrapped instance is also passed as the first argument.
This instance for chaining.
node
.run(function (context) {
console.log(this.ref)
console.log(context.ref)
})
.trigger(new Event('ready'))
Replaces the existing children of an Element with new children.
The children to replace with.
This instance for chaining.
If no children are provided, it empties the Element.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Maps an array to children and replaces the existing children with the result.
This instance for chaining.
This is the mapping companion to setChildren.
To make template codes easier, this function ignores mapped nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Errors thrown by the mapping function or child replacement are wrapped with a higher-level error that preserves the original cause.
Replaces the existing children of an Element with an array of children.
The children to replace with.
This instance for chaining.
This is the array-based companion to setChild.
Passing an empty array empties the Element.
To make template codes easier, this function ignores nullish children (null and undefined).
Other non-node values are coerced into Text nodes.
Clones and sets template-like input as the only children of this node.
This instance for chaining.
Supports HTML strings, native template sources, native Nodes, and any JJ wrapper via JJN. Wrapper inputs are unwrapped and cloned before set.
Dispatches an Event at the specified EventTarget.
The Event object to dispatch.
This instance for chaining.
Creates and dispatches a CustomEvent on the wrapped target.
This instance for chaining.
This is a convenience wrapper around trigger for the common case of dispatching a payload-bearing custom event.
The created event defaults to bubbles: true and composed: true.
Pass options to override those defaults.
StaticfromCreates a JJD instance from a Document reference.
The Document instance.
A new JJD instance.
StaticisChecks if a value can be passed to the wrap() or unwrap() function.
an unknown value
true if x is a string, Node (or its descendent), JJN (or its descendent)
This is useful for filtering the array that is passed to append(), prepend() or setChildren().
See Wrappable type for the full definition.
StaticunwrapExtracts the underlying native DOM node from a wrapper.
The value to unwrap.
The underlying DOM node.
If the input is already a native Node, it is returned as is.
If the input is a JJ wrapper, its underlying node is returned.
Otherwise, the input is coerced into a Text node.
Plain objects are stringified with JSON when possible, and fall back to String(...).
StaticunwrapUnwraps an iterable object (e.g. an array or HTMLCollection).
The iterable to unwrap.
An array of native DOM nodes.
StaticwrapWraps a native DOM node or string into the most specific JJ wrapper available.
The object to wrap. If it's already Wrapped, it'll be returned without any change. We don't double-wrap or clone it.
The most granular Wrapped subclass instance. If the input is already wrapped, it'll be returned as is without cloning.
This factory function acts as an intelligent wrapper, inspecting the input type and returning the appropriate
subclass of JJN (e.g., JJHE for HTMLElement, JJT for Text, JJSE for SVGElement, etc.).
Strings are automatically converted to Text nodes wrapped in JJT.
If the input is already a JJ wrapper, it is returned unchanged (no double-wrapping). See the full implementation in src/wrappers/JJN.ts which extends this with support for internal wrapper types.
const bodyWrapper = JJN.wrap(document.body) // Returns JJHE<HTMLBodyElement>
const textWrapper = JJN.wrap('Hello') // Returns JJT wrapping a new Text node
const existing = JJN.wrap(alreadyWrapped) // Returns alreadyWrapped unchanged
StaticwrapWraps an iterable object (e.g. an array of wrapped or DOM elements).
The iterable to wrap.
An array of wrapped instances.
Wraps a Document (which is a descendant of Node).
Remarks
This class provides a wrapper around the native
Documentinterface, inheriting the fluent API capabilities ofJJN. It also supports querying (find) and manipulation (addChild,preChild) methods.To find elements by class name, use:
doc.find('.my-class')To set the document title, use:
doc.ref.title = 'New Title'Example
See
Document