0

I'm creating a standard calculator in a reactjs projects. There is a button which calculates x power 2 for that i'm using html element <sup> to do that but that is not working

<Button name = "x<sup>2</sup>" clickHandler = {this.buttonClickHandler} />

Button element is created from this code:

<button onClick = {this.buttonClickHandler}>{this.props.name}</button>

I want to show text like this x2enter image description here

Ashok Gadri
  • 520
  • 4
  • 11

1 Answers1

1

You need to use dangerouslySetInnerHTML like this:

<button onClick={this.buttonClickHandler} dangerouslySetInnerHTML={{__html: this.props.name}} />

--- Original post below, because the author didn't specified the "x²" was coming from React ---

Buttons doesn't work like inputs. They are regular tags (that don't close themselves), and their contents is between the opening and the closing tag.

You don't want <button name="THE CONTENT" />.

You want <button>THE CONTENT</button>

So in your case, you can just do this:

<button clickHandler = {this.buttonClickHandler}>x<sup>2</sup></button>
HeySora
  • 846
  • 7
  • 19