What would be the output on the button click? (Event Handling)
@Yomesh Gupta
<div id="grandfather">
<div id="father">
<!-- What would be the output in the console if the following button#child is clicked -->
<button id="child">Click Me</button>
</div>
</div>
<script type="text/javascript">
function bindEvent(id) {
document
.getElementById(id)
.addEventListener(
"click",
(e) => console.log(e.target.getAttribute("id")),
true
);
}
bindEvent("grandfather");
bindEvent("father");
bindEvent("child");
</script>
Option 1
child father grandfather
Option 2
grandfather father child
Option 3
child child child
Option 4
undefined undefined undefined