Good all the time of day.

How to access an element in a single handler method?

class FirstContainer extends Component { constructor(props){ super(props); } getCLk(){ console.log(this.refs.txt); } render(){ return ( <ul> <li onClick={this.getCLk.bind(this)} ref="txt" key={0}>FIRST</li> <li onClick={this.getCLk.bind(this)} ref="txt" key={1}>SECOND</li> </ul> ); } } 

It would be desirable, that the element on which clicked was selected. Now the last one is chosen. Is it possible to describe this in one method and not put different ref?

Thanks in advance.

  • Can I have a little more detail, what do you want to do? - Ilya Paymushkin

1 answer 1

 getCLk(e){ console.log(e.target); } 

Refs are not needed in this case.