Answers for "Detecting clicks outside of an element (or inside)"

0

Detecting clicks outside of an element (or inside)

window.addEventListener('mousedown', e => {
  // Get the element that was clicked
  const clickedEl = e.target;

  // `el` is the element you're detecting clicks outside of
  if (el.contains(clickedEl)) {
    // Clicked inside of `el`
  } else {
    // Clicked outside of `el`
  }
});
Posted by: Guest on July-28-2021

Code answers related to "Detecting clicks outside of an element (or inside)"

Code answers related to "Javascript"

Browse Popular Code Answers by Language