Answers for "get id button clicked react"

0

get id button clicked react

class Button extends React.Component {

  handleId = (e) => {
   /*Well if the elements are nested event.target won't always work
     since it refers to the target that triggers the event in the first place.*/
    console.log(e.target.id);
    console.log(e.currentTarget.id);
  }

  render() {
    return (
      <button id="yourID" onClick={this.handleId}>Button</button>
    );
  }
}
Posted by: Guest on June-21-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language