Skip to content

Instantly share code, notes, and snippets.

@mbparvezme
Last active March 4, 2024 07:27
Show Gist options
  • Save mbparvezme/ed6e56dab034013ecd73ba6c811f02c9 to your computer and use it in GitHub Desktop.
Save mbparvezme/ed6e56dab034013ecd73ba6c811f02c9 to your computer and use it in GitHub Desktop.
This code will check whether you clicked inside the target or not
var targetElem = document.querySelector("#sidebar");
window.addEventListener('click',function(e){
if( !targetElem.contains(e.target) && (!document.getElementById('navSwitch').contains(e.target))){
$(targetElem).removeClass('open')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment