React – onClick captures children as target rather than parent

Posted on

I placed  some data in the parent div that I wanted to use when the div was clicked.

Using was not working because I was getting the children elements as the target and not the parent div as I wanted.

div  onClick={this.handleClick} name={}  //want this as event target h2 
Welcome h2
h3 {} h3
h4 Item found in: {Item.location} h4


The fix was below:

handleClick = (event)=>{
const target =



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s