V
V
Vladimir2020-05-18 20:58:37
React
Vladimir, 2020-05-18 20:58:37

How to get the text of an element on click in react?

Good evening. Please tell me how can I get the text of the element when clicked, I try like this, but it does not work, but with iteration through forEacth(el => el.onclick = () => el.innerText)) the situation is similar, but there are no errors .

<li onClick={console.log(this.innerText)}>Item 2</li>


Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-05-18
@HistoryART

onClick={ (e) => console.log(e.target.innerText) }
it's just plain javascript

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question