get element or elements check functions

PHOTO EMBED

Wed Mar 22 2023 00:46:04 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #get #element #function

export const getElement = (selection) => {
  const element = document.querySelector(selection);
  if (element) {
    return element;
  }
  throw new Error(
    `Please check "${selection}" selector, no such element exists`
  );
}


export const getAllElements = (elements) => {
    const allelements = document.querySelectorAll(elements);
    if(allelements){
      return allelements
    }
    throw new Error(`These ${elements} cannot be found`)
}
content_copyCOPY