Question : e.target.id not working react js
Answered by : vivacious-vole-eq68haku7725
//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. See this link for the usage of event.currentTarget,
//which always refer to the element that the handler is bound to.
class Button extends React.Component { getButtonId = (e) => { console.log(e.currentTarget.id); } render() { return ( <button id="yourID" onClick={this.getButtonId}>Button</button> ); }
}
Source : | Last Update : Mon, 25 Jul 22