Skip to content

Instantly share code, notes, and snippets.

@b-aleksei
Created September 2, 2021 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b-aleksei/29eebb808161f4d09c82f7d2467577ea to your computer and use it in GitHub Desktop.
Save b-aleksei/29eebb808161f4d09c82f7d2467577ea to your computer and use it in GitHub Desktop.
ToolTip
export const tooltipToggle = (btn) => {
const content = btn.nextElementSibling;
if (!content) return;
content.classList.toggle('active');
if (content.classList.contains('active')) {
const closeContent = ({target}) => {
if (!content.contains(target) ) {
content.classList.remove('active');
document.removeEventListener('click', closeContent);
}
};
document.addEventListener('click', closeContent);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment