I have a div that contains some buttons and I want to attach an event listener to the div that listens for events that bubble up from the buttons inside of it.
The problem I am running into is that the value of event.currentTarget
does not appear to match what the docs say it should.
Consider the following code:
$('.container').on('click', '.myButton', function(event) {
console.log("event.currentTarget:");
console.log(event.currentTarget);
console.log("event.target: ");
console.log(event.target);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div class="container">
<button class="myButton">Click Me</button>
</div>
I am using jquery 1.8.3
event.currentTarget
should be the container div, but it is being set to the button inside it instead.
How can I get around this. Is this a known bug or am I doing something wrong?