change style on click react
JavaScript
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:
- Title
- import jquery
- Category
- JavaScript
- Title
- for loop js example
- Category
- JavaScript
- Title
- how to freeze js object
- Category
- JavaScript
- Title
- append img to svg d3 js
- Category
- JavaScript
- Title
- defineCall is not a function at Sequelize.import sequelize.js
- Category
- JavaScript
- Title
- import axios react
- Category
- JavaScript
- Title
- insert into specific array index that has a value existing on that index
- Category
- JavaScript
- Title
- get date one week from now javascript
- Category
- JavaScript
- Title
- dotenv not loading process.env in node
- Category
- JavaScript
- Title
- import reactdom
- Category
- JavaScript
- Title
- disabling submit button until all fields have values
- Category
- JavaScript
- Title
- Angularjs datetime
- Category
- JavaScript
- Title
- how to delete an element from an array in javascript
- Category
- JavaScript
- Title
- how to change image source using javascript
- Category
- JavaScript
- Title
- how to do a classname variable and string react
- Category
- JavaScript
- Title
- alert user javascript
- Category
- JavaScript
- Title
- browser detect javascript
- Category
- JavaScript
- Title
- faker js
- Category
- JavaScript
- Title
- how the sort function works javascript
- Category
- JavaScript
- Title
- callback without duplicates javascript
- Category
- JavaScript
- Title
- bash parse json
- Category
- JavaScript
- Title
- how to code print in javascript
- Category
- JavaScript
- Title
- convert class object to json python
- Category
- JavaScript
- Title
- chart.js data from mysql vanila javscript
- Category
- JavaScript
- Title
- how to get user ip address in javascript
- Category
- JavaScript
- Title
- create react app theme_color
- Category
- JavaScript
- Title
- how to get selected row index of table in javascript
- Category
- JavaScript
- Title
- generate bearer token
- Category
- JavaScript
- Title
- how to import a json string from a file in typescript
- Category
- JavaScript
- Title
- how to see if a web site is useing react
- Category
- JavaScript
- Title
- .shift js
- Category
- JavaScript
- Title
- How to get the path to the file that required your module?
- Category
- JavaScript
- Title
- enter event in jquery
- Category
- JavaScript
- Title
- get number right of the dot length javascript
- Category
- JavaScript
- Title
- call javascript function after page load complete
- Category
- JavaScript
- Title
- javascript Check if an element is a descendant of another
- Category
- JavaScript
- Title
- http content type json
- Category
- JavaScript
- Title
- fill array with values javascript
- Category
- JavaScript
- Title
- javascript clear file input
- Category
- JavaScript
- Title
- add 2 class names react
- Category
- JavaScript
- Title
- array find method javascript
- Category
- JavaScript
- Title
- html parser javascript
- Category
- JavaScript
- Title
- Enclose in Brackets
- Category
- JavaScript
- Title
- angular onchange event
- Category
- JavaScript
- Title
- combine p5 with react
- Category
- JavaScript
- Title
- go to another page using javascript
- Category
- JavaScript
- Title
- angular rebuild
- Category
- JavaScript
- Title
- if back react
- Category
- JavaScript
- Title
- add webpack to react project
- Category
- JavaScript
- Title
- isogram
- Category
- JavaScript
- Title
- devexpress dxdatagrid custom text field link
- Category
- JavaScript
- Title
- class javascript
- Category
- JavaScript
- Title
- codemirror get object from textarea
- Category
- JavaScript
- Title
- input not detecting text
- Category
- JavaScript
- Title
- how to show hide div in html javascript
- Category
- JavaScript
- Title
- angular router return back
- Category
- JavaScript
- Title
- get utc time javascript
- Category
- JavaScript
- Title
- how to set diferent images in html through js
- Category
- JavaScript
- Title
- definicion de un componente en angular
- Category
- JavaScript
- Title
- javascript add multiple items to array
- Category
- JavaScript
- Title
- getelementbyclass
- Category
- JavaScript
- Title
- how to initialize an array in javascript
- Category
- JavaScript
- Title
- curl post json object command
- Category
- JavaScript
- Title
- how to detect a button click in javascript
- Category
- JavaScript
- Title
- Date gethours js
- Category
- JavaScript
- Title
- how to align text inside react component
- Category
- JavaScript
- Title
- get value javascript
- Category
- JavaScript
- Title
- change select value jquery
- Category
- JavaScript
- Title
- flatten nested object js
- Category
- JavaScript
- Title
- how to make fizzbuzz in javascript
- Category
- JavaScript
- Title
- form taglib in jsp
- Category
- JavaScript
- Title
- how to create a variable in javascript
- Category
- JavaScript
- Title
- window location in react
- Category
- JavaScript
- Title
- how to define variable in javascript
- Category
- JavaScript
- Title
- how to use custom stylesheets express node
- Category
- JavaScript
- Title
- check if variable is undefined or null jquery
- Category
- JavaScript
- Title
- how to remove session data on tab close in redux\
- Category
- JavaScript
- Title
- get data from json using jquery
- Category
- JavaScript
- Title
- edit onclick event
- Category
- JavaScript
- Title
- for each python json
- Category
- JavaScript
- Title
- chart js rotating the x axis labels
- Category
- JavaScript
- Title
- how to update angular version
- Category
- JavaScript
- Title
- create react component class
- Category
- JavaScript
- Title
- how to get the last element of an array in javascript
- Category
- JavaScript
- Title
- how to write img jsx
- Category
- JavaScript
- Title
- get all a tags javascript
- Category
- JavaScript
- Title
- angular run with proxy
- Category
- JavaScript
- Title
- build filter js
- Category
- JavaScript
- Title
- ellipsis javascript
- Category
- JavaScript
- Title
- how to check chrome version in js
- Category
- JavaScript
- Title
- how to use for of in javascript
- Category
- JavaScript
- Title
- discord.js dm user
- Category
- JavaScript
- Title
- how to push multiple data to different parents in a single request in firebase
- Category
- JavaScript
- Title
- check if number appears odd number of times in array javascript
- Category
- JavaScript
- Title
- connect nodejs to mariadb
- Category
- JavaScript
- Title
- how to remove link in image in jquery
- Category
- JavaScript
- Title
- how to get the size of the window in javascript
- Category
- JavaScript
- Title
- how to access global scope in to local scope using javascript examples
- Category
- JavaScript
- Title
- form validation react
- Category
- JavaScript
- Title
- ionic cordova icon notification
- Category
- JavaScript