Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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>
    );
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #id #button #clicked #react
ADD COMMENT
Topic
Name
9+8 =