change style on click react
Html
<div id="app"></div>
Css
button{
width: 80px;
height: 40px;
margin: 15px;
}
.blackButton{
background-color: black;
color: white;
}
.whiteButton{
background-color: white;
color: black;
}
React
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 (
<div>
<button className={btn_class}
onClick={this.changeColor.bind(this)}>
Button
</button>
</div>
)
}
}
ReactDOM.render(<Test />, document.querySelector("#app"))
Also in JavaScript:
- javascript randomly shuffle array
- convert excel file to json using node js
- add checkbox dynamically in javascript
- packages.json from file
- array unique values javascript
- set navigation drawer to open by default react native
- popper js example
- UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
- content editable vuejs
- add property to object javascript
- js loop through associative array
- node js return json
- js in_array
- how to check if you click something in javascript
- json object check if key exists java
- how can prevent morgan to work in test enviroment
- select a form by name jquery
- js replace all symbols in string
- js copy array into another
- tolocalestring javascript currency fixing 2 decimal places
- Javascript check if undefined
- jquery check if screen size
- p5 js lines
- host angular app on node server