Skip to content

Instantly share code, notes, and snippets.

@ozknozsrt
Created September 16, 2022 13:00
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 ozknozsrt/2fece80ee8a72e4695ded10e46c6159f to your computer and use it in GitHub Desktop.
Save ozknozsrt/2fece80ee8a72e4695ded10e46c6159f to your computer and use it in GitHub Desktop.
click outside with javascript composedPath()
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