0

When setting the onClick event in the following way:

<button type="button" field={this.props.name} onClick={this.props.add_item}> <i className="fa fa-plus"></i> </button> 

In the end I want to get the field attribute from the event target.

Now the problem: When I click on the button area i'll get the field attribute, but when clicked the child it also triggers the event but from a different target element (it has no field attribute; ...which I could set of course). But isn't there a better way to make the whole element trigger from the same target or something like that?

2 Answers 2

1

I think you should use event.currentTarget instead of event.target

Sign up to request clarification or add additional context in comments.

Comments

0

You can make the parent click handler to be fired on clicking both the child and parent by binding another click handler in the child element calling event.stopPropagation().
If you are using new browsers, then applying the following CSS to your <i> element should solve the problem:

pointer-events: none; 

See browser compatibility.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.