Skip to content

Instantly share code, notes, and snippets.

@oguzhancvdr
Last active May 31, 2023 18:39
Show Gist options
  • Save oguzhancvdr/f1957b73f4d149d0720f404977be2d4a to your computer and use it in GitHub Desktop.
Save oguzhancvdr/f1957b73f4d149d0720f404977be2d4a to your computer and use it in GitHub Desktop.
// Traverse up the DOM tree to find an element with data-place-id attribute
let targetElement = e.target;
while (targetElement && !targetElement.dataset.placeId) {
targetElement = targetElement.parentElement;
}
// Retrieve the data-place-id attribute value
const placeId = targetElement ? targetElement.dataset.placeId : undefined;
@oguzhancvdr
Copy link
Author

Find closest element with data-place-id attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment