How can I get the innerHTML of a clicked button [duplicate]

29
June 16, 2019, at 12:30 PM

This question already has an answer here:

  • Are 'Arrow Functions' and 'Functions' equivalent / exchangeable? 3 answers
  • How does the “this” keyword work? 23 answers

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

READ ALSO
Function that is intended to return an array is returning undefined. Console.log(array) within function returns the array

Function that is intended to return an array is returning undefined. Console.log(array) within function returns the array

I am trying to write a function that takes an array and returns a new array with all elements shifted n indices to the leftFor example:

72
Selenium Actions moveToElement on Google Chrome 75.0.3770.80 on ubuntu doesnot work

Selenium Actions moveToElement on Google Chrome 75.0.3770.80 on ubuntu doesnot work

Selected an element and wanted --> physically move the mouse cursor over it

37
React hook setState arguments

React hook setState arguments

I would like to know the difference between the following two versions of codeBoth versions do the same

59