dom-helpers
- Version 5.2.1
- Published
- 127 kB
- 2 dependencies
- MIT license
Install
npm i dom-helpers
yarn add dom-helpers
pnpm add dom-helpers
Overview
tiny modular DOM lib for ie9+
Index
Variables
Functions
- activeElement()
- addClass()
- addEventListener()
- animate()
- attribute()
- cancelAnimationFrame()
- childElements()
- childNodes()
- clear()
- closest()
- contains()
- filter()
- getComputedStyle()
- hasClass()
- height()
- insertAfter()
- isInput()
- isVisible()
- listen()
- matches()
- nextUntil()
- offset()
- offsetParent()
- ownerDocument()
- ownerWindow()
- parents()
- position()
- prepend()
- querySelectorAll()
- remove()
- removeClass()
- removeEventListener()
- scrollbarSize()
- scrollParent()
- scrollTo()
- siblings()
- style()
- text()
- toggleClass()
- transitionEnd()
- triggerEvent()
- width()
Variables
variable _default
const _default: { addEventListener: typeof addEventListener; removeEventListener: typeof removeEventListener; triggerEvent: typeof triggerEvent; animate: typeof animate; filter: typeof filter; listen: typeof listen; style: typeof style; getComputedStyle: typeof getComputedStyle; attribute: typeof attribute; activeElement: typeof activeElement; ownerDocument: typeof ownerDocument; ownerWindow: typeof ownerWindow; requestAnimationFrame: typeof globalThis.requestAnimationFrame; cancelAnimationFrame: (id: number) => void; matches: typeof matches; height: typeof height; width: typeof width; offset: typeof offset; offsetParent: typeof offsetParent; position: typeof position; contains: typeof contains; scrollbarSize: typeof scrollbarSize; scrollLeft: { (node: Element): number; (node: Element, val: number): undefined }; scrollParent: typeof scrollParent; scrollTo: typeof scrollTo; scrollTop: { (node: Element): number; (node: Element, val: number): undefined }; querySelectorAll: typeof querySelectorAll; closest: typeof closest; addClass: typeof addClass; removeClass: typeof removeClass; hasClass: typeof hasClass; toggleClass: typeof toggleClass; transitionEnd: typeof transitionEnd; childNodes: typeof childNodes; childElements: typeof childElements; nextUntil: typeof nextUntil; parents: typeof parents; siblings: typeof siblings; clear: typeof clear; insertAfter: typeof insertAfter; isInput: typeof isInput; isVisible: typeof isVisible; prepend: typeof prepend; remove: typeof remove; text: typeof text;};
variable requestAnimationFrame
const requestAnimationFrame: (callback: FrameRequestCallback) => number;
variable scrollLeft
const scrollLeft: { (node: Element): number; (node: Element, val: number): undefined;};
variable scrollTop
const scrollTop: { (node: Element): number; (node: Element, val: number): undefined;};
Functions
function activeElement
activeElement: (doc?: Document) => Element | null;
Returns the actively focused element safely.
Parameter doc
the document to check
function addClass
addClass: (element: Element | SVGElement, className: string) => void;
Adds a CSS class to a given element.
Parameter element
the element
Parameter className
the CSS class name
function addEventListener
addEventListener: <K extends keyof HTMLElementEventMap>( node: HTMLElement, eventName: K, handler: TaggedEventHandler<K>, options?: boolean | AddEventListenerOptions) => void;
An
addEventListener
ponyfill, supports theonce
optionParameter node
the element
Parameter eventName
the event name
Parameter handle
the handler
Parameter options
event options
function animate
animate: { (options: Options): Cancel; (node: HTMLElement, properties: AnimateProperties, duration: number): Cancel; ( node: HTMLElement, properties: AnimateProperties, duration: number, callback: EventHandler<'transitionend'> ): Cancel; ( node: HTMLElement, properties: AnimateProperties, duration: number, easing: string, callback: EventHandler<'transitionend'> ): Cancel;};
function attribute
attribute: ( node: Element | null, attr: string, val?: string | boolean | null) => string | null | undefined;
Gets or sets an attribute of a given element.
Parameter node
the element
Parameter attr
the attribute to get or set
Parameter val
the attribute value
function cancelAnimationFrame
cancelAnimationFrame: (id: number) => void;
function childElements
childElements: (node: Element | null) => Element[];
Collects all child elements of an element.
Parameter node
the element
function childNodes
childNodes: (node: Element | null) => Node[];
Collects all child nodes of an element.
Parameter node
the node
function clear
clear: (node: Node | null) => Node | null;
Removes all child nodes from a given node.
Parameter node
the node to clear
function closest
closest: (node: Element, selector: string, stopAt?: Element) => Element | null;
Returns the closest parent element that matches a given selector.
Parameter node
the reference element
Parameter selector
the selector to match
Parameter stopAt
stop traversing when this element is found
function contains
contains: (context: Element, node: Element) => boolean | undefined;
Checks if an element contains another given element.
Parameter context
the context element
Parameter node
the element to check
function filter
filter: <K extends keyof HTMLElementEventMap>( selector: string, handler: EventHandler<K>) => EventHandler<K>;
function getComputedStyle
getComputedStyle: ( node: HTMLElement, psuedoElement?: string) => CSSStyleDeclaration;
Returns one or all computed style properties of an element.
Parameter node
the element
Parameter psuedoElement
the style property
function hasClass
hasClass: (element: Element | SVGElement, className: string) => boolean;
Checks if a given element has a CSS class.
Parameter element
the element
Parameter className
the CSS class name
function height
height: (node: HTMLElement, client?: boolean) => number;
Returns the height of a given element.
Parameter node
the element
Parameter client
whether to use
clientHeight
if possible
function insertAfter
insertAfter: (node: Node | null, refNode: Node | null) => Node | null;
Inserts a node after a given reference node.
Parameter node
the node to insert
Parameter refNode
the reference node
function isInput
isInput: (node: Element | null) => boolean;
Checks if a given element is an input (input, select, textarea or button).
Parameter node
the element to check
function isVisible
isVisible: (node: HTMLElement | null) => boolean;
Checks if a given element is currently visible.
Parameter node
the element to check
function listen
listen: <K extends keyof HTMLElementEventMap>( node: HTMLElement, eventName: K, handler: EventHandler<K>, options?: boolean | AddEventListenerOptions) => () => void;
function matches
matches: (node: Element, selector: string) => boolean;
Checks if a given element matches a selector.
Parameter node
the element
Parameter selector
the selector
function nextUntil
nextUntil: (node: Element | null, selector: string) => Element[];
Collects all next sibling elements of an element until a given selector is matched.
Parameter node
the referene node
Parameter selector
the selector to match
function offset
offset: (node: HTMLElement) => { top: number; left: number; height: number; width: number;};
Returns the offset of a given element, including top and left positions, width and height.
Parameter node
the element
function offsetParent
offsetParent: (node: HTMLElement) => HTMLElement;
function ownerDocument
ownerDocument: (node?: Element) => Document;
Returns the owner document of a given element.
Parameter node
the element
function ownerWindow
ownerWindow: (node?: Element) => Window;
Returns the owner window of a given element.
Parameter node
the element
function parents
parents: (node: Element | null) => Element[];
Collects all parent elements of a given element.
Parameter node
the element
function position
position: ( node: HTMLElement, offsetParent?: HTMLElement) => { top: number; left: number; height: number; width: number };
Returns the relative position of a given element.
Parameter node
the element
Parameter offsetParent
the offset parent
function prepend
prepend: (node: Element | null, parent: Element | null) => Element | null;
Insert a given element as the first child of a parent element.
Parameter node
the element to prepend
Parameter parent
the parent element
function querySelectorAll
querySelectorAll: ( element: HTMLElement | Document, selector: string) => HTMLElement[];
Runs
querySelectorAll
on a given element.Parameter element
the element
Parameter selector
the selector
function remove
remove: (node: Node | null) => Node | null;
Removes a given node from the DOM.
Parameter node
the node to remove
function removeClass
removeClass: (element: Element | SVGElement, className: string) => void;
Removes a CSS class from a given element.
Parameter element
the element
Parameter className
the CSS class name
function removeEventListener
removeEventListener: <K extends keyof HTMLElementEventMap>( node: HTMLElement, eventName: K, handler: TaggedEventHandler<K>, options?: boolean | EventListenerOptions) => void;
A
removeEventListener
ponyfillParameter node
the element
Parameter eventName
the event name
Parameter handle
the handler
Parameter options
event options
function scrollbarSize
scrollbarSize: (recalc?: boolean) => number;
function scrollParent
scrollParent: ( element: HTMLElement, firstPossible?: boolean) => Document | HTMLElement;
Find the first scrollable parent of an element.
Parameter element
Starting element
Parameter firstPossible
Stop at the first scrollable parent, even if it's not currently scrollable
function scrollTo
scrollTo: ( selected: HTMLElement, scrollParent?: HTMLElement) => (() => void) | undefined;
function siblings
siblings: (node: Element | null) => Element[];
Collects all previous and next sibling elements of a given element.
Parameter node
the element
function style
style: { (node: HTMLElement, property: Partial<Record<Property, string>>): void; <T extends string | number | symbol>( node: HTMLElement, property: T ): CSS.PropertiesHyphen; <T extends string | number | symbol>( node: HTMLElement, property: T ): CSS.Properties;};
function text
text: ( node: HTMLElement | null, trim?: boolean, singleSpaces?: boolean) => string;
Collects the text content of a given element.
Parameter node
the element
Parameter trim
whether to remove trailing whitespace chars
Parameter singleSpaces
whether to convert multiple whitespace chars into a single space character
function toggleClass
toggleClass: (element: Element | SVGElement, className: string) => void;
Toggles a CSS class on a given element.
Parameter element
the element
Parameter className
the CSS class name
function transitionEnd
transitionEnd: ( element: HTMLElement, handler: Listener, duration?: number | null, padding?: number) => () => void;
function triggerEvent
triggerEvent: <K extends keyof HTMLElementEventMap>( node: HTMLElement | null, eventName: K, bubbles?: boolean, cancelable?: boolean) => void;
Triggers an event on a given element.
Parameter node
the element
Parameter eventName
the event name to trigger
Parameter bubbles
whether the event should bubble up
Parameter cancelable
whether the event should be cancelable
function width
width: (node: HTMLElement, client?: boolean) => number;
Returns the width of a given element.
Parameter node
the element
Parameter client
whether to use
clientWidth
if possible
Package Files (45)
- cjs/activeElement.d.ts
- cjs/addClass.d.ts
- cjs/addEventListener.d.ts
- cjs/animate.d.ts
- cjs/animationFrame.d.ts
- cjs/attribute.d.ts
- cjs/childElements.d.ts
- cjs/childNodes.d.ts
- cjs/clear.d.ts
- cjs/closest.d.ts
- cjs/contains.d.ts
- cjs/css.d.ts
- cjs/filterEventHandler.d.ts
- cjs/getComputedStyle.d.ts
- cjs/hasClass.d.ts
- cjs/height.d.ts
- cjs/index.d.ts
- cjs/insertAfter.d.ts
- cjs/isInput.d.ts
- cjs/isVisible.d.ts
- cjs/listen.d.ts
- cjs/matches.d.ts
- cjs/nextUntil.d.ts
- cjs/offset.d.ts
- cjs/offsetParent.d.ts
- cjs/ownerDocument.d.ts
- cjs/ownerWindow.d.ts
- cjs/parents.d.ts
- cjs/position.d.ts
- cjs/prepend.d.ts
- cjs/querySelectorAll.d.ts
- cjs/remove.d.ts
- cjs/removeClass.d.ts
- cjs/removeEventListener.d.ts
- cjs/scrollLeft.d.ts
- cjs/scrollParent.d.ts
- cjs/scrollTo.d.ts
- cjs/scrollTop.d.ts
- cjs/scrollbarSize.d.ts
- cjs/siblings.d.ts
- cjs/text.d.ts
- cjs/toggleClass.d.ts
- cjs/transitionEnd.d.ts
- cjs/triggerEvent.d.ts
- cjs/width.d.ts
Dependencies (2)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/dom-helpers
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/dom-helpers)
- HTML<a href="https://www.jsdocs.io/package/dom-helpers"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 1803 ms. - Missing or incorrect documentation? Open an issue for this package.