I want to pass the innerHTML of a clicked button to the onClick method in React. How can I do that? Please note, I am not asking about the arrow notation; I am asking how to get the innerHTML of the button so that I can pass it as an argument.
This is how I am creating the buttons:
var buttons = [];
for (let i = 0; i < 4; i++) {
buttons.push(
<button onClick={() => props.handleClick(this.correctAnswers, this.innerHTML)}>
{currentAnswers[i]}
</button>
)
}
return <div >{buttons}</div>;}
and this is my onClick method
handleClick(correctAnswers, inner) {
alert(correctAnswers)
alert(inner)
}
The handleClick() doesn't do anything yet. I'm just trying to pass in the values for now. alert(inner) is undefined. Thanks