Answers for "how to determine if click is $el or outside"

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
0

how to detect click outside div

$(window).click(function() {
  //Hide the menus if visible
});

$('#menucontainer').click(function(event){
  event.stopPropagation();
});
Posted by: Guest on November-24-2021

Code answers related to "how to determine if click is $el or outside"

Code answers related to "Javascript"

Browse Popular Code Answers by Language