J
J
Jedi2020-06-08 10:51:58
React
Jedi, 2020-06-08 10:51:58

Why does onClick propagate to child element?

Hello! Something strange...

<li className="mdc-list-item" tabIndex="0" key={i} data-user-id={user.id} onClick={this.startChat}>
     <span className="mdc-list-item__text">{user.name} {user.surname}</span>
</li>


startChat(event) {
     console.log(event.target.getAttribute('data-user-id'))
}


this.startChat = this.startChat.bind(this);

5eddedd3abbb3889239179.png

When I click on the edges, respectively, this is lian element, I get the expected. But when I click on the center, where it lives span, I get null .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alex4answ, 2020-06-08
@PHPjedi

Because the event pops up

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question