tweb/src/helpers/dom/findUpClassName.ts
Eduard Kuzmenko 866d1c05ef Forums
2023-01-06 23:27:29 +04:00

19 lines
605 B
TypeScript

/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
// export function findUpClassName<T>(el: any, className: string): T;
export default function findUpClassName(el: EventTarget | {closest: (selector: string) => any}, className: string): HTMLElement {
return (el as any).closest('.' + className);
/* if(el.classList.contains(className)) return el; // 03.02.2020
while(el.parentElement) {
el = el.parentElement;
if(el.classList.contains(className))
return el;
}
return null; */
}