Options
All
  • Public
  • Public/Protected
  • All
Menu

dom-lib

Index

Properties

contains: (context: Element, node: Node & ParentNode) => boolean

Type declaration

    • (context: Element, node: Node & ParentNode): boolean
    • Checks if an element contains another given element.

      Parameters

      • context: Element

        The context element

      • node: Node & ParentNode

        The element to check

      Returns boolean

      true if the given element is contained, false otherwise

Variables

canUseDOM: boolean = !!( typeof window !== 'undefined' && window.document && window.document.createElement )

Checks if the current environment is in the browser and can access and modify the DOM.

Functions

  • addClass(target: Element, className: string): Element
  • Adds specific class to a given element

    Parameters

    • target: Element

      The element to add class to

    • className: string

      The class to be added

    Returns Element

    The target element

  • addStyle(node: Element, property: string, value: string | number): void
  • addStyle(node: Element, properties: Partial<CSSProperty>): void
  • Apply a single CSS style rule to a given element

    Parameters

    • node: Element

      The element to add styles to

    • property: string

      The style property to be added

    • value: string | number

      The style value to be added

    Returns void

  • Apply multiple CSS style rules to a given element

    Parameters

    • node: Element

      The element to add styles to

    • properties: Partial<CSSProperty>

      The key-value object of style properties to be added

    Returns void

  • cancelAnimationFramePolyfill(handle: number): void
  • deprecated

    use cancelAnimationFrame instead

    Parameters

    • handle: number

    Returns void

  • getAnimationEnd(): any
  • Returns any

  • getContainer(container: Element | (() => Element), defaultContainer?: Element): Element
  • Get a DOM container

    Parameters

    • container: Element | (() => Element)
    • Optional defaultContainer: Element

    Returns Element

  • getHeight(node: Element | Window, client?: Element): number
  • Get the height of a DOM element

    Parameters

    • node: Element | Window

      The DOM element

    • Optional client: Element

      Whether to get the client height

    Returns number

    The height of the DOM element

  • getOffset(node: Element): Offset | DOMRect | null
  • Get the offset of a DOM element

    Parameters

    • node: Element

      The DOM element

    Returns Offset | DOMRect | null

    The offset of the DOM element

  • getOffsetParent(node: Element): Element
  • Get the offset parent of a DOM element

    Parameters

    • node: Element

      The DOM element

    Returns Element

    The offset parent of the DOM element

  • getPosition(node: Element, offsetParent?: Element, calcMargin?: boolean): Offset | DOMRect | null
  • Get the position of a DOM element

    Parameters

    • node: Element

      The DOM element

    • Optional offsetParent: Element

      The offset parent of the DOM element

    • calcMargin: boolean = true

      Whether to calculate the margin

    Returns Offset | DOMRect | null

    The position of the DOM element

  • getScrollbarSize(recalc?: boolean): number | void
  • Returns the size of the scrollbar.

    Parameters

    • Optional recalc: boolean

      Force recalculation.

    Returns number | void

    The size of the scrollbar.

  • getStyle(node: Element, property?: string): string | CSSStyleDeclaration
  • Gets the value for a style property

    Parameters

    • node: Element

      The DOM element

    • Optional property: string

      The style property

    Returns string | CSSStyleDeclaration

    The value of the style property

  • getWidth(node: Element | Window, client?: Element): number
  • Get the width of a DOM element

    Parameters

    • node: Element | Window

      The DOM element

    • Optional client: Element

      Whether to get the client width

    Returns number

    The width of the DOM element

  • getWindow(node: any): Window
  • Get the Window object of browser

    Parameters

    • node: any

      The DOM element

    Returns Window

    The Window object of browser

  • hasClass(target: Element, className: string): boolean
  • Check whether an element has a specific class

    Parameters

    • target: Element

      The element to be checked

    • className: string

      The class to be checked

    Returns boolean

    true if the element has the class, false otherwise

  • isFocusable(element: Element): boolean
  • Checks whether element is focusable or not.

    isFocusable(document.querySelector("input")); // true
    isFocusable(document.querySelector("input[tabindex='-1']")); // true
    isFocusable(document.querySelector("input[hidden]")); // false
    isFocusable(document.querySelector("input:disabled")); // false

    Parameters

    • element: Element

    Returns boolean

  • isOverflowing(container: Element): boolean
  • Check if the document is overflowing and account for the scrollbar width

    Parameters

    • container: Element

      The container to check

    Returns boolean

    The document is overflowing

  • nodeName(node: Element): string
  • Get the name of the DOM element

    Parameters

    • node: Element

      The DOM element

    Returns string

    The name of the DOM element

  • off<K>(target: Element | EventTarget | Window | Document, eventName: K, listener: EventListenerOrEventListenerObject | CustomEventListener<any>, options?: boolean | AddEventListenerOptions): void
  • Unbind target event eventName's callback listener.

    Type parameters

    • K: keyof DocumentEventMap

    Parameters

    • target: Element | EventTarget | Window | Document

      The DOM element

    • eventName: K

      The event name

    • listener: EventListenerOrEventListenerObject | CustomEventListener<any>

      The event listener

    • options: boolean | AddEventListenerOptions = false

      The event options

    Returns void

  • on<K>(target: Element | EventTarget | Window | Document, eventType: K, listener: EventListenerOrEventListenerObject | CustomEventListener<any>, options?: boolean | AddEventListenerOptions): { off: any }
  • Bind target event eventName's callback listener.

    Type parameters

    • K: keyof DocumentEventMap

    Parameters

    • target: Element | EventTarget | Window | Document

      The DOM element

    • eventType: K

      The event name

    • listener: EventListenerOrEventListenerObject | CustomEventListener<any>

      The event listener

    • options: boolean | AddEventListenerOptions = false

      The event options

    Returns { off: any }

    The event listener

    • off:function
      • off(): void
      • Returns void

  • ownerDocument(node: Element): Document
  • Returns the top-level document object of the node.

    Parameters

    • node: Element

      The DOM element

    Returns Document

    The top-level document object of the node

  • ownerWindow(componentOrElement: Element): Window
  • Returns the top-level window object of the node.

    Parameters

    • componentOrElement: Element

      The DOM element

    Returns Window

    The top-level window object of the node

  • removeClass(target: Element, className: string): Element
  • Remove a class from a given element

    Parameters

    • target: Element

      The element to remove the class from

    • className: string

      The class to be removed

    Returns Element

    The target element

  • removeStyle(node: Element, keys: string | string[]): void
  • Remove a style property from a DOM element

    Parameters

    • node: Element

      The DOM element

    • keys: string | string[]

      key(s) typeof [string , array]

    Returns void

  • requestAnimationFramePolyfill(callback: FrameRequestCallback): number
  • deprecated

    Use requestAnimationFrame instead.

    Parameters

    • callback: FrameRequestCallback

    Returns number

  • scrollLeft(node: Element): number
  • scrollLeft(node: Element, val: number): void
  • Gets the number of pixels to scroll the element's content from the left edge.

    Parameters

    • node: Element

      The DOM element

    Returns number

  • Sets the number of pixels to scroll the element's content from its left edge.

    Parameters

    • node: Element

      The DOM element

    • val: number

      The number of pixels to scroll the element's content from its left edge

    Returns void

  • scrollTop(node: Element): number
  • scrollTop(node: Element, val: number): void
  • Gets the number of pixels that an element's content is scrolled vertically.

    Parameters

    • node: Element

      The DOM element

    Returns number

  • Sets the number of pixels that an element's content is scrolled vertically.

    Parameters

    • node: Element

      The DOM element

    • val: number

      The number of pixels that an element's content is scrolled vertically

    Returns void

  • toggleClass(target: Element, className: string): Element
  • Toggle a class on an element

    Parameters

    • target: Element

      The DOM element

    • className: string

      The class name

    Returns Element

    The DOM element

  • translateDOMPositionXY(style: CSSStyleDeclaration, x?: number, y?: number): CSSStyleDeclaration
  • Parameters

    • style: CSSStyleDeclaration
    • x: number = 0
    • y: number = 0

    Returns CSSStyleDeclaration

Generated using TypeDoc