Thursday, December 14, 2017

React toggle Class Name on click

getInitialState: function() {
    return {
      myclass: "ravish"
    }
  },
  handleClick: function() {
var temp="ravish";
if( this.state.myclass=="ravish"){
  temp="ravish open"
}
this.setState({
      myclass: temp
    });


<div id="change button" className={this.state.myclass} onClick={this.handleClick} ></div>

No comments:

Post a Comment