index.ts 650 B

123456789101112131415161718
  1. // @ts-nocheck
  2. export function findClosestElementWithStyle(startEl: UniElement | null, styleProperty: string): UniElement | null {
  3. let currentEl: UniElement | null = startEl;
  4. while (currentEl != null) {
  5. // Check if the current element has the style property with a non-empty value
  6. const styleValue = currentEl?.style.getPropertyValue(styleProperty) ?? '';
  7. if (styleValue.trim() != '') {
  8. return currentEl;
  9. }
  10. // Move to parent element
  11. currentEl = currentEl.parentElement;
  12. }
  13. // Return null if no element with the specified style was found
  14. return null;
  15. };