Created
September 2, 2021 17:53
-
-
Save b-aleksei/29eebb808161f4d09c82f7d2467577ea to your computer and use it in GitHub Desktop.
ToolTip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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