UNPKG

@jay-js/system

Version:

A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.

25 lines (24 loc) 1.3 kB
/** * Selects all elements matching the specified CSS selector within the target element (or the entire document if no target is provided). * * @param selector - A string containing one or more comma-separated CSS selectors. * @param target - The HTML element or Document within which to search. If not provided, defaults to the entire document. * @returns A NodeList of found elements. Returns an empty NodeList if no elements match the selector. */ export function selectors(selector, target = document) { if (!target || typeof selector !== 'string') { throw new Error('Invalid parameters'); } return target.querySelectorAll(selector); } /** * Selects the first element matching the specified CSS selector within the target element (or the entire document if no target is provided). * * @param selector - A string containing a valid CSS selector. * @param target - The HTML element or Document within which to search. If not provided, defaults to the entire document. * @returns The first element found that matches the selector, or null if no elements match. */ export function selector(selector1, target = document) { if (!target || typeof selector1 !== 'string') { throw new Error('Invalid parameters'); } return target.querySelector(selector1); }