Created
September 16, 2022 13:00
-
-
Save ozknozsrt/2fece80ee8a72e4695ded10e46c6159f to your computer and use it in GitHub Desktop.
click outside with javascript composedPath()
This file contains hidden or 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
const box = document.querySelector(".box"); | |
document.addEventListener("click", function(e) { | |
if(e.composedPath().includes(box)) { | |
console.log("clicked inside it!") | |
} else { | |
console.log("clicked outside it!") | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment