Creates an instance of JJHE.
The HTMLElement to wrap.
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.
Adds one or more classes to the Element.
The classes to add.
This instance for chaining.
Adds multiple classes from an array of class names.
The classes to add.
This instance for chaining.
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.
Finds the closest ancestor (or self) that matches a CSS selector.
The CSS selector to search for.
A JJE wrapping the closest match, or null when none exists.
Disables the Element by setting the disabled attribute and aria-disabled="true".
This instance for chaining.
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.
Gets the value of an ARIA attribute.
The ARIA attribute suffix (e.g., 'label' for 'aria-label').
The attribute value, or null if not present.
Gets the value of an attribute.
The name of the attribute.
The attribute value, or null if not present.
Gets the class attribute.
The class attribute value, or null if not present.
Gets a data attribute from the element.
The data attribute name (in camelCase).
The value of the attribute, or undefined if not set.
Gets the inner HTML of the Element.
The inner HTML string.
Gets the value of a single inline style property.
The CSS property name (kebab-case recommended).
The property value, or an empty string when it is not set.
Gets the inner text of the HTMLElement.
The inner text.
Gets the value property of the HTMLElement (e.g. for inputs).
The value.
Checks if an ARIA attribute exists.
The ARIA attribute suffix.
true if the attribute exists.
Checks if an attribute exists.
The name of the attribute.
true if the attribute exists, otherwise false.
Checks if the Element has a specific class.
The class to check for.
true if the element has the class.
Checks if a data attribute exists on the element.
The data attribute name (in camelCase).
True if the attribute exists, false otherwise.
Hides the Element by setting the hidden attribute and aria-hidden="true".
This instance for chaining.
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.
Replaces a class with another one
The class name to remove
The class name to add
Removes this node from its parent.
This instance for chaining.
Removes one or more ARIA attributes from the Element.
The ARIA attribute suffix(es) to remove.
This instance for chaining.
Removes one or more attributes from the Element.
The name(s) of the attribute(s) to remove.
This instance for chaining.
Removes one or more classes from the Element.
The classes to remove.
This instance for chaining.
Removes multiple classes from an array of class names.
The classes to remove.
This instance for chaining.
Removes one or more data attributes from the element.
The data attribute name(s) (in camelCase).
This instance for chaining.
Removes multiple data attributes from an array of names.
The data attribute names to remove (in camelCase).
This instance for chaining.
Removes one or more inline style properties.
The CSS property names to remove.
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'))
Sets a single ARIA attribute on the Element.
The ARIA attribute suffix.
The value to assign.
This instance for chaining.
Sets multiple ARIA attributes from an object, or no-ops for nullish input.
Optionalattributes: Record<string, unknown> | nullARIA attributes object or nullish to skip.
This instance for chaining.
This helper is useful for optional ARIA attribute bags in builder APIs.
null or undefined: does nothing and returns thisTypeErrorSets a single attribute on the Element.
Sets multiple attributes from an object, or no-ops for nullish input.
Optionalattributes: Record<string, unknown> | nullAttributes object or nullish to skip.
This instance for chaining.
This helper is useful for optional attribute bags in builder APIs.
null or undefined: does nothing and returns thisTypeErrorsetAttr for setting a single attribute.
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.
Sets the class attribute.
The full class attribute value.
This instance for chaining.
Conditionally adds or removes classes from an object map, or no-ops for nullish input.
OptionalclassMap: Record<string, unknown> | nullConditional class map or nullish to skip.
This instance for chaining.
null or undefined: does nothing and returns thisTypeErrorel.setClasses({
active: true,
disabled: false,
highlight: isHighlighted,
})
el.setClasses(null) // no-op
Sets a single data attribute on the element.
The data attribute name (in camelCase).
Optionalvalue: stringThe value to assign.
This instance for chaining.
Sets multiple data attributes from an object, or no-ops for nullish input.
Optionalattributes: Record<string, string | undefined> | nullData attributes object or nullish to skip.
This instance for chaining.
This helper is useful for optional dataset bags in builder APIs.
null or undefined: does nothing and returns thisTypeErrorSets the inner HTML of the Element.
The HTML string to set, or null/undefined to clear.
Optionalunsafe: booleanexplicit opt-in to set innerHTML. must be true if html is provided.
This instance for chaining.
Attaches a Shadow DOM to the Element if it's not already attached.
The encapsulation mode ('open' or 'closed'). Defaults to 'open'.
Optionaltemplate: Optional content to initialize the shadow DOM, which can be a string, DocumentFragment, HTMLTemplateElement, HTMLElement, or any JJ wrapper.
Optional styles to add to the shadow DOM, which can be strings or CSSStyleSheet instances.
This instance for chaining.
Sets a single inline style property.
The CSS property name (kebab-case recommended).
The CSS property value.
This instance for chaining.
Sets or removes multiple inline style properties from an object map, or no-ops for nullish input.
OptionalstyleMap: Record<string, unknown> | nullStyle property map or nullish to skip.
This instance for chaining.
null or undefined: does nothing and returns thisnull/undefined/false remove propertiesTypeErrorel.setStyles({
display: 'grid',
gap: '1rem',
opacity: 0,
color: null,
})
el.setStyles(null) // no-op
setStyle for setting a single style property.
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.
Sets the inner text of the HTMLElement.
Optionaltext: unknownThe text to set, or null/undefined to clear.
This instance for chaining.
Sets the value property of the HTMLElement.
The value to set.
This instance for chaining.
Toggles a class on the Element.
The class to toggle.
This instance for chaining.
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.
StaticcreateCreates a JJHE instance from a tag name.
The tag name.
Optionaloptions: ElementCreationOptionsElement creation options.
A new JJHE instance.
For existing HTMLElements, use JJHE.from instead. For SVG or MathML elements, use JJSE.create or JJME.create respectively.
Creates a JJHE instance from a tag name.
The tag name.
Optionaloptions: ElementCreationOptionsElement creation options.
A new JJHE instance.
For existing HTMLElements, use JJHE.from instead. For SVG or MathML elements, use JJSE.create or JJME.create respectively.
StaticfromCreates a JJHE instance from an HTMLElement reference.
The HTMLElement.
A new JJHE instance.
Use JJHE.create to create new HTMLElements, or use this method to wrap existing ones. For other element types, use JJSE.from for SVGElements or JJME.from for MathMLElements.
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.
StatictreeBuilds an HTML element tree with optional attributes and children.
The HTML tag name.
Optionalattributes: Record<string, string> | nullAttributes to set. Pass null or undefined to skip.
Children to append (strings, nodes, or JJ wrappers).
A new JJHE instance.
A concise declarative way to build HTML DOM snippets. Chain further JJ methods on the return value.
Pass null or omit attributes when no attributes are needed. Pass children as additional arguments.
Unlike create(), the return type is always JJHE (not the specific subtype), which is fine for
snippet construction where precise inference is not needed.
If you prefer a shorter alias compatible with hyperscript conventions, you can use:
const h = JJHE.tree
// Simple element with text
JJHE.tree('p', { class: 'intro' }, 'Hello World')
// Nested structure
JJHE.tree('nav', { class: 'main-nav' },
JJHE.tree('a', { href: '/' }, 'Home'),
JJHE.tree('a', { href: '/about' }, 'About'),
)
// No attributes
JJHE.tree('section', null, JJHE.tree('h1', null, 'Title'), JJHE.tree('p', null, 'Body'))
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 DOM HTMLElement (which is a descendant of Element).
Remarks
This class extends
JJEto provide specific functionality for HTML elements, such as access todataset,innerText, and form values.See
HTMLElement