I have situation Like I have a Wrapper div
and a Child div
and I am doing console.log('any text')
when I am clicking the Wrapper div
its is consoling the text {which makes sense to me} But When I am clicking the Child div
it Still consoles the Text. {Which is weird
let test = document.querySelector('.test')
test.addEventListener('click', function() {
console.log('wrapper clicked')
})
.test{
width:100%;
heightL:100vh;
display: flex;
justify-content: center;
align-items:center;
}
.exam{
height: 100vh;
width: 50%;
color:white;
font-family:sans-serif;
display: grid;
place-items:center;
background: #000;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="test">
<div class="exam">
<h1>Click Me</h1>
</div>
</div>
</body>
</html>
to me}
So I want to know why this is happening Like when I am clicking the Child div
why it Still consoles the text?
and How to make it only console the text when the wrapper is clicked not the child?