Is it possible to change background-color
of my button onClick
function?
ex. click background-color: black
, another click
You can try to use state to store the color. Maybe this would give you the idea how to solve the problem :
class Test extends React.Component {
constructor(){
super();
this.state = {
black: true
}
}
changeColor(){
this.setState({black: !this.state.black})
}
render(){
let btn_class = this.state.black ? "blackButton" : "whiteButton";
return (
)
}
}
React.render( , document.getElementById('container'));
Here is a fiddle.