DOM

DOM

Source:

Methods

(static) $<E extends Element = Element>(selectors, multiopt) → {E | NodeListOf<E> | null}

Source:
Checks if the specified class value exists in the element's class attribute.
Name Type Description
selectors string | ... A DOMString containing one or more selectors to match
multi? boolean | ... If multi is true, a DOMString containing one or more selectors to match against.

$<K extends keyof HTMLElementTagNameMap>(selectors, multi) → {NodeListOf<HTMLElementTagNameMap[K]>}

Name Type Description
selectors K
multi true

$<K extends keyof SVGElementTagNameMap>(selectors, multi) → {NodeListOf<SVGElementTagNameMap[K]>}

Name Type Description
selectors K
multi true

$<E extends Element = Element>(selectors, multi) → {NodeListOf<E>}

Name Type Description
selectors string
multi true

$<K extends keyof HTMLElementTagNameMap>(selectors, multi) → {HTMLElementTagNameMap[K] | null}

Name Type Description
selectors K
multi? false

$<K extends keyof SVGElementTagNameMap>(selectors, multi) → {SVGElementTagNameMap[K] | null}

Name Type Description
selectors K
multi? false

$<E extends Element = Element>(selectors, multi) → {E | null}

Name Type Description
selectors string
multi? false
Example
import {$} from "@daybrush/utils";

console.log($("div")); // div element
console.log($("div", true)); // [div, div] elements
Returns:
Type
E | NodeListOf<E> | null

(static) addClass(element, className)

Source:
Add the specified class value. If these classe already exist in the element's class attribute they are ignored.
Name Type Description
element Element target
className string the class name to add
Example
import {addClass} from "@daybrush/utils";

addClass(element, "start");

(static) addEvent<K extends keyof IEventMap>(el, type, listener, optionsopt) → {void}

Source:
Sets up a function that will be called whenever the specified event is delivered to the target
Name Type Description
el EventTarget event target
type string | ... A case-sensitive string representing the event type to listen for.
listener (e: Event) => void | ... The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs
options? boolean | AddEventListenerOptions An options object that specifies characteristics about the event listener.

addEvent<K extends keyof IEventMap>(el, type, listener, options) → {void}

Name Type Description
el EventTarget
type K
listener (e: IEventMap[K]) => void
options? boolean | AddEventListenerOptions
Example
import {addEvent} from "@daybrush/utils";

addEvent(el, "click", e => {
  console.log(e);
});
Returns:
Type
void

(static) fromCSS(elements, properites) → {IObject<any>}

Source:
Gets the CSS properties from the element.
Name Type Description
elements Element | Element[] | NodeListOf<Element> elements
properites string[] the CSS properties
Example
import {fromCSS} from "@daybrush/utils";

console.log(fromCSS(element, ["left", "opacity", "top"])); // {"left": "10px", "opacity": 1, "top": "10px"}
Returns:
returns CSS properties and values.
Type
IObject<any>

(static) hasClass(element, className) → {boolean}

Source:
Checks if the specified class value exists in the element's class attribute.
Name Type Description
element Element target
className string the class name to search
Example
import {hasClass} from "@daybrush/utils";

console.log(hasClass(element, "start")); // true or false
Returns:
return false if the class is not found.
Type
boolean

(static) removeClass(element, className)

Source:
Removes the specified class value.
Name Type Description
element Element target
className string the class name to remove
Example
import {removeClass} from "@daybrush/utils";

removeClass(element, "start");

(static) removeEvent<K extends keyof IEventMap>(el, type, listener, optionsopt) → {void}

Source:
removes from the EventTarget an event listener previously registered with EventTarget.addEventListener()
Name Type Description
el EventTarget event target
type string | ... A case-sensitive string representing the event type to listen for.
listener (e: Event) => void | ... The EventListener function of the event handler to remove from the event target.
options? boolean | EventListenerOptions An options object that specifies characteristics about the event listener.

removeEvent<K extends keyof IEventMap>(el, type, listener, options) → {void}

Name Type Description
el EventTarget
type K
listener (e: IEventMap[K]) => void
options? boolean | EventListenerOptions
Example
import {addEvent, removeEvent} from "@daybrush/utils";
const listener = e => {
  console.log(e);
};
addEvent(el, "click", listener);
removeEvent(el, "click", listener);
Returns:
Type
void