Class Element

Class representing a generic DOM element with utility methods for manipulation and validation.

Constructors

Accessors

Methods

  • Adds an event listener to the element.

    Parameters

    • type: string

      The event type to listen for.

    • handler: (e: Event) => void

      The event handler function.

    • Optionalonce: boolean

      Whether the event should only fire once.

    Returns () => void

    A function to remove the event listener, or undefined if the element is not suitable for events.

  • Gets the value of an attribute.

    Parameters

    • attribute: string

      The attribute name.

    Returns string

    The value of the attribute or null if not found.

  • Adds a blur event listener to the element.

    Parameters

    • handler: (e: Event) => void

      The event handler function.

    • Optionalonce: boolean

      Whether the event should only fire once.

    Returns () => void

    A function to remove the event listener.

  • Finds all elements with the specified class name within this element's scope.

    Parameters

    • className: string

      The class name to match.

    Returns Element[]

    An array of Element instances.

  • Finds the first element matching the CSS selector within this element's scope.

    Parameters

    • selector: string

      The CSS selector to match.

    Returns Element

    The Element instance if found, null otherwise.

  • Finds all elements matching the CSS selector within this element's scope.

    Parameters

    • selector: string

      The CSS selector to match.

    Returns Element[]

    An array of Element instances.

  • Finds all elements with the specified tag name within this element's scope.

    Parameters

    • tagName: string

      The tag name to match.

    Returns Element[]

    An array of Element instances.

  • Adds a change event listener to the element.

    Parameters

    • handler: (e: Event) => void

      The event handler function.

    • Optionalonce: boolean

      Whether the event should only fire once.

    Returns () => void

    A function to remove the event listener.

  • Adds a click event listener to the element.

    Parameters

    • handler: (e: Event) => void

      The event handler function.

    • Optionalonce: boolean

      Whether the event should only fire once.

    Returns () => void

    A function to remove the event listener.

  • Gets the value of a data attribute.

    Parameters

    • attribute: string

      The data attribute name.

    Returns string

    The value of the data attribute.

  • Adds a focus event listener to the element.

    Parameters

    • handler: (e: Event) => void

      The event handler function.

    • Optionalonce: boolean

      Whether the event should only fire once.

    Returns () => void

    A function to remove the event listener.

  • Checks if the element has a specific class.

    Parameters

    • className: string

      The class name to check.

    Returns boolean

    True if the element has the class, false otherwise.

  • Adds a keydown event listener to the element.

    Parameters

    • handler: (e: KeyboardEvent) => void

      The keyboard event handler function.

    • Optionalonce: boolean

      Whether the event should only fire once.

    Returns () => void

    A function to remove the event listener.

  • Adds a keyup event listener to the element.

    Parameters

    • handler: (e: KeyboardEvent) => void

      The keyboard event handler function.

    • Optionalonce: boolean

      Whether the event should only fire once.

    Returns () => void

    A function to remove the event listener.

  • Removes a specific class from the element.

    Parameters

    • className: string

      The class name to remove.

    Returns void

  • Gets or sets the value of the input element.

    Parameters

    • Optionalvalue: string

      Optional value to set for the input element. If no value is provided, it returns the current value of the input element. If a value is provided, it sets the input element's value to that value. This method is useful for both getting and setting the value of input elements.

    Returns string

    The value of the input element.

  • Finds all elements with the specified class name. When called as static method: searches entire document. When called as instance method: searches within this element's scope.

    Parameters

    • className: string

      The class name to match.

    Returns Element[]

    An array of Element instances.

  • Finds an element by its ID. When called as static method: searches entire document. When called as instance method: searches within this element's scope.

    Parameters

    • id: string

      The ID of the element to find.

    Returns Element

    The Element instance if found, null otherwise.

  • Finds the first element matching the CSS selector. When called as static method: searches entire document. When called as instance method: searches within this element's scope.

    Parameters

    • selector: string

      The CSS selector to match.

    Returns Element

    The Element instance if found, null otherwise.

  • Finds all elements matching the CSS selector. When called as static method: searches entire document. When called as instance method: searches within this element's scope.

    Parameters

    • selector: string

      The CSS selector to match.

    Returns Element[]

    An array of Element instances.

  • Finds all elements with the specified tag name. When called as static method: searches entire document. When called as instance method: searches within this element's scope.

    Parameters

    • tagName: string

      The tag name to match.

    Returns Element[]

    An array of Element instances.