UNPKG

domkitjs

Version:

A dom manipulation package for all your needs!

52 lines (51 loc) 1.98 kB
/** * Shortcut for document.querySelector that works exactly like it but returns `false` if no element is found. * Automatically waits for the DOM to be ready. * * @param {string} selector - The CSS selector to match the element. * @returns {Promise<HTMLElement | false>} The found HTML element or `false` if no element is found. * * @example * // Querying selector and waiting for the DOM to be ready * const elem = await qry('#my-element'); * if (elem) { * console.log('Element found:', elem); * } else { * console.log('Element not found'); * } */ export declare function qry(selector: string): Promise<HTMLElement | false>; /** * Shortcut for document.querySelectorAll that works exactly like it but returns `false` if no elements are found. * Automatically waits for the DOM to be ready. * * @param {string} selector - The CSS selector to match the elements. * @returns {Promise<NodeListOf<HTMLElement> | false>} A NodeList of found HTML elements or `false` if no elements are found. * * @example * // Querying selector and waiting for the DOM to be ready * const elems = await qryAll('.list-item'); * if (elems) { * elems.forEach(elem => console.log('Element found:', elem)); * } else { * console.log('No elements found'); * } */ export declare function qryAll(selector: string): Promise<NodeListOf<HTMLElement> | false>; /** * Shortcut for document.getElementById that works exactly like it but returns `false` if no element is found. * Automatically waits for the DOM to be ready. * * @param {string} id - The id of the element to find. * @returns {Promise<HTMLElement | false>} The found HTML element or `false` if no element is found. * * @example * // Querying ID and waiting for the DOM to be ready * const elem = await id('header'); * if (elem) { * console.log('Element found:', elem); * } else { * console.log('Element not found'); * } */ export declare function qryById(id: string): Promise<HTMLElement | false>;