I have a div with a button inside, i want to create separate click events for both but when the button is clicked it is firing the button event and the container event. Can someone help me out. I'm not using jQuery.
var button = document.querySelector('button');
button.addEventListener('click', function(){
alert('button clicked');
})
var container = document.querySelector('.container');
container.addEventListener('click', function(){
alert('container clicked');
})
.container{
width:300px;
height:300px;
border:1px solid;
position:relative;
z-index:1;
}
button{
position:absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
z-index:2;
}
<div class="container">
<button>click</button>
</div>