stay on target. stay on current-target16 Mar 2017
I was setting up an event handler in jQuery today. I want to move to React or Vue, but just not there yet.
Unfortunately, I was looking at the
target instead of the
currentTarget. Basically if you have
HTML like this:
<button class="outer" data-blah="something"> <i class="inner">something</i> </button>
$(document).on("click", ".outer", callSomeFunction);
Then, depending on whether you click on the inner or the outer element, the
event.target will point to the
inner or outer element (i.e what you actually clicked on, not what you’ve bound the delegated event to)
However, if you use
event.currentTarget all will be well in the world.