tickle/modules/utils/getElement.mjs

19 lines
615 B
JavaScript
Raw Normal View History

2023-06-07 20:07:47 +00:00
//@ts-check
import {isElement} from "./isElement.mjs";
/**
* Little utility so people can pass css selectors or elements in initialization
* options.
* A minimal replacement to a more full fledged selector engine like jQuery
* @param {string|HTMLElement} elementOrString
* @returns {HTMLElement | null}
*/
export const getElement = (elementOrString) => {
const element =
elementOrString && typeof elementOrString === "string"
? /** @type {HTMLElement}*/ (document.querySelector(elementOrString))
: elementOrString;
return isElement(element) ? element : null;
};
export default getElement