1var ignoreClickOnMeElement = document.getElementById('someElementID');
2
3document.addEventListener('click', function(event) {
4 var isClickInsideElement = ignoreClickOnMeElement.contains(event.target);
5 if (!isClickInsideElement) {
6 //Do something click is outside specified element
7 }
8});
1$(document).click((event) => {
2 if (!$(event.target).closest('#element').length) {
3 // the click occured outside '#element'
4 }
5});
1document.addEventListener("click", (evt) => {
2 const flyoutElement = document.getElementById("flyout-example");
3 let targetElement = evt.target; // clicked element
4
5 do {
6 if (targetElement == flyoutElement) {
7 // This is a click inside. Do nothing, just return.
8 document.getElementById("flyout-debug").textContent = "Clicked inside!";
9 return;
10 }
11 // Go up the DOM
12 targetElement = targetElement.parentNode;
13 } while (targetElement);
14
15 // This is a click outside.
16 document.getElementById("flyout-debug").textContent = "Clicked outside!";
17});
18