Hi guys am trying to come up with javascript code thats popularly applied in detecting click area to close an element like a sidenav or a floating div whenever the user clicks outside the element, the click outside works and closes the element but whenever i click inside my element, it still dissappears, here is my code:
<script>
var y = document.getElementById("advert");
window.onclick = function(event){
if (event.target == y){
y.style.display = "none";
} else {
y.style.display = "block";
}
}
</script>