94
rated 0 times
[
99]
[
5]
/ answers: 1 / hits: 22899
/ 7 Years ago, fri, november 3, 2017, 12:00:00
<!DOCTYPE html>
<html>
<head>
<style>
.dropdown-content a{
display: block;
background-color: blue;
}
</style>
</head>
<body>
<div class=dropdown-content>
<a>1</a>
<a>2</a>
</div>
<script>
window.onclick = function(event){
if(!event.target.matches('.dropdown-content')){
alert(foo);
}
};
</script>
</body>
</html>
I'm trying to make alert(foo);
execute only when we are NOT clicking on anything inside of the div
tag in the body. Unfortunately, it executes no matter where I click. Why?
More From » jquery