I am trying to get the event of button on clicking it. I have an image inside the button.
<button onClick={this.selectSubject} value="PHYSICS" className="button-blue"><img src={Magnet} />PHYSICS</button>
When i click on button i get event as
<button value="PHYSICS" class="button-blue"><img src="/static/media/magnet.d8028ed2.svg">PHYSICS</button>
But when i click specifically on image i get event of image tag as
<img src="/static/media/magnet.d8028ed2.svg">
Its expected behaviour should be that i get event of button element. Why this is happening.
It looks like you are using
event.targetto get the clicked element. In this case target won't be button every time you click. It always refers to the element got the event fired upon.I would suggest you to use
event.currentTargetwhich will always be the element which is bound to the event.