0.6.0 • Published 4 years ago

@tyframe/util v0.6.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

@tyframe/util

Functions

closest

Returns first parent element of given element, which matches the given selector.

const element = document.querySelector('.test');
const closestElement = closest(element, '.parent');

delegate

Add an event delegation to document.

The first argument can also be an element, an element array, a node list of elements or a css selector.

delegate(
    document,
    '.test',
    'click',
    (event: Event): void => {
        console.log('click');
    },
    false,
);

siblings

Find all siblings of given element, optionally filtered by a selector.

const element = document.querySelector('button.test');
const siblings = siblings(element, '.test');

trigger

Execute all handlers and behaviors attached to the matched elements for the given event type.

const exampleButton = document.querySelector('.example');
if (exampleButton !== null) {
    trigger(exampleButton, 'click');
}