Created
July 6, 2017 09:06
-
-
Save maliMirkec/fd36aec429662ac4af26aece83ee0072 to your computer and use it in GitHub Desktop.
Listen to click off element in vanilla JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var specifiedElement = document.getElementById('a'); | |
//I'm using "click" but it works with any event | |
document.addEventListener('click', function(event) { | |
var isClickInside = specifiedElement.contains(event.target); | |
if (!isClickInside) { | |
//the click was outside the specifiedElement, do something | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment