Reputation: 273
I have the following button with event attached:
<button className="pull-right btn btn-success" onClick={this.onNextStep}>Next</button>
OnNextStep:
onNextStep: function (e) {
...
}
How do I get the button name inside onNextStep?
e.target.value is not working
And how do I change it?
Upvotes: 1
Views: 4047
Reputation: 24815
I would suggest something like this:
<button
type="button"
className="pull-right btn btn-success"
onClick={() => this.onNextStep('Next')}
>
Next
</button>
Remember that React is mostly about writing to the DOM. Rarely do you read from it. (The exception being inputs.)
Your "value" is just a static piece of text. There is no need to get what you've already got.
Upvotes: 1
Reputation: 395
You need a name attribute on that button name="next step"
and you'll get it via e.target.name
. To change it you could assign name={this.state.buttonName}
and set state on that key when you need to (this.setState({ buttonName: "new button name" });
). If you are talking about inner HTML as in the comment by Matthew, your button's name could be called from state <button>{this.state.name}</button>
and setState could change that as well.
Upvotes: 0